From 66f8166bd0501a159e2eecad77cc92b0b3beb38e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 18 Sep 2009 20:01:33 -0700 Subject: First pass at LocalGridServiceConnector. Nothing of this is used by the simulator yet. --- .../Grid/LocalGridServiceConnector.cs | 175 +++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs new file mode 100644 index 0000000..6475817 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs @@ -0,0 +1,175 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using Nini.Config; +using System; +using System.Collections.Generic; +using System.Reflection; +using OpenSim.Framework; +using OpenSim.Server.Base; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using OpenMetaverse; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid +{ + public class LocalGridServicesConnector : + ISharedRegionModule, IGridService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private IGridService m_GridService; + + private bool m_Enabled = false; + + #region ISharedRegionModule + + public Type ReplaceableInterface + { + get { return null; } + } + + public string Name + { + get { return "LocalGridServicesConnector"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("GridServices", ""); + if (name == Name) + { + IConfig assetConfig = source.Configs["GridService"]; + if (assetConfig == null) + { + m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); + return; + } + + string serviceDll = assetConfig.GetString("LocalServiceModule", + String.Empty); + + if (serviceDll == String.Empty) + { + m_log.Error("[GRID CONNECTOR]: No LocalServiceModule named in section GridService"); + return; + } + + Object[] args = new Object[] { source }; + m_GridService = + ServerUtils.LoadPlugin(serviceDll, + args); + + if (m_GridService == null) + { + m_log.Error("[GRID CONNECTOR]: Can't load asset service"); + return; + } + m_Enabled = true; + m_log.Info("[GRID CONNECTOR]: Local grid connector enabled"); + } + } + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + } + + public void RegionLoaded(Scene scene) + { + } + + #endregion + + #region IGridService + + public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) + { + return m_GridService.RegisterRegion(scopeID, regionInfo); + } + + public bool DeregisterRegion(UUID regionID) + { + return m_GridService.DeregisterRegion(regionID); + } + + public List GetNeighbours(UUID scopeID, int x, int y) + { + return m_GridService.GetNeighbours(scopeID, x, y); + } + + public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) + { + return m_GridService.GetRegionByUUID(scopeID, regionID); + } + + public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) + { + return m_GridService.GetRegionByPosition(scopeID, x, y); + } + + public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) + { + return m_GridService.GetRegionByName(scopeID, regionName); + } + + public List GetRegionsByName(UUID scopeID, string name, int maxNumber) + { + return m_GridService.GetRegionsByName(scopeID, name, maxNumber); + } + + public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) + { + return m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax); + } + + #endregion + } +} -- cgit v1.1 From 390137d540b9ae39eba3ba9136bd49d5e992bc5f Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 21 Sep 2009 11:05:01 -0700 Subject: Added grid handler and grid remote connector. --- .../ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 6475817..74ece2e 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs @@ -140,9 +140,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return m_GridService.DeregisterRegion(regionID); } - public List GetNeighbours(UUID scopeID, int x, int y) + public List GetNeighbours(UUID scopeID, UUID regionID) { - return m_GridService.GetNeighbours(scopeID, x, y); + return m_GridService.GetNeighbours(scopeID, regionID); } public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) -- cgit v1.1 From a9ced0fe7962654be7bf7282babd475761f8bb50 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 21 Sep 2009 19:33:56 -0700 Subject: Added Remote grid connector module. --- .../Grid/RemoteGridServiceConnector.cs | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs new file mode 100644 index 0000000..b0cfc9c --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs @@ -0,0 +1,108 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using System; +using System.Collections.Generic; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Services.Connectors; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid +{ + public class RemoteGridServicesConnector : + GridServicesConnector, ISharedRegionModule, IGridService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private bool m_Enabled = false; + + public Type ReplaceableInterface + { + get { return null; } + } + + public string Name + { + get { return "RemoteGridServicesConnector"; } + } + + public override void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("GridServices", ""); + if (name == Name) + { + IConfig gridConfig = source.Configs["GridService"]; + if (gridConfig == null) + { + m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); + return; + } + + m_Enabled = true; + + base.Initialise(source); + + m_log.Info("[GRID CONNECTOR]: Remote grid enabled"); + } + } + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + } + + public void RegionLoaded(Scene scene) + { + } + } +} -- cgit v1.1 From 34f4738159300ab6370e3db47df5187b6cea8771 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 22 Sep 2009 11:58:40 -0700 Subject: Added HGGridConnector and related code. --- .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 304 +++++++++++++++++++++ .../Grid/LocalGridServiceConnector.cs | 64 +++-- .../Grid/RemoteGridServiceConnector.cs | 34 ++- 3 files changed, 364 insertions(+), 38 deletions(-) create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs new file mode 100644 index 0000000..b7e3213 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -0,0 +1,304 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Reflection; + +using OpenSim.Framework; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using OpenSim.Server.Base; +using OpenSim.Services.Connectors.Grid; + +using OpenMetaverse; +using log4net; +using Nini.Config; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid +{ + public class HGGridConnector : ISharedRegionModule, IGridService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private bool m_Enabled = false; + private bool m_Initialized = false; + + private IGridService m_GridServiceConnector; + private HypergridServiceConnector m_HypergridServiceConnector; + + // Hyperlink regions are hyperlinks on the map + protected Dictionary m_HyperlinkRegions = new Dictionary(); + + // Known regions are home regions of visiting foreign users. + // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when + // the visitor goes away. They are mapped to X=0 on the map. + // This is key-ed on agent ID + protected Dictionary m_knownRegions = new Dictionary(); + + #region ISharedRegionModule + + public Type ReplaceableInterface + { + get { return null; } + } + + public string Name + { + get { return "HGGridServicesConnector"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("GridServices", ""); + if (name == Name) + { + IConfig gridConfig = source.Configs["GridService"]; + if (gridConfig == null) + { + m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini"); + return; + } + + + InitialiseConnectorModule(source); + + m_Enabled = true; + m_log.Info("[HGGRID CONNECTOR]: HG grid enabled"); + } + } + } + + private void InitialiseConnectorModule(IConfigSource source) + { + IConfig gridConfig = source.Configs["GridService"]; + if (gridConfig == null) + { + m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini"); + throw new Exception("Grid connector init error"); + } + + string module = gridConfig.GetString("GridServiceConnectorModule", String.Empty); + if (module == String.Empty) + { + m_log.Error("[HGGRID CONNECTOR]: No GridServiceConnectorModule named in section GridService"); + //return; + throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); + } + + Object[] args = new Object[] { source }; + m_GridServiceConnector = ServerUtils.LoadPlugin(module, args); + + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + } + + public void RegionLoaded(Scene scene) + { + if (m_Enabled && !m_Initialized) + { + m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); + m_Initialized = true; + } + } + + #endregion + + #region IGridService + + public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) + { + // Region doesn't exist here. Trying to link remote region + if (regionInfo.RegionID.Equals(UUID.Zero)) + { + m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort); + regionInfo.RegionID = m_HypergridServiceConnector.LinkRegion(regionInfo); + if (!regionInfo.RegionID.Equals(UUID.Zero)) + { + m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); + m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID); + + // Try get the map image + m_HypergridServiceConnector.GetMapImage(regionInfo); + return true; + } + else + { + m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")"); + return false; + } + // Note that these remote regions aren't registered in localBackend, so return null, no local listeners + } + else // normal grid + return m_GridServiceConnector.RegisterRegion(scopeID, regionInfo); + } + + public bool DeregisterRegion(UUID regionID) + { + // Try the hyperlink collection + if (m_HyperlinkRegions.ContainsKey(regionID)) + { + m_HyperlinkRegions.Remove(regionID); + return true; + } + // Try the foreign users home collection + if (m_knownRegions.ContainsKey(regionID)) + { + m_knownRegions.Remove(regionID); + return true; + } + // Finally, try the normal route + return m_GridServiceConnector.DeregisterRegion(regionID); + } + + public List GetNeighbours(UUID scopeID, UUID regionID) + { + // No serving neighbours on hyperliked regions. + // Just the regular regions. + return m_GridServiceConnector.GetNeighbours(scopeID, regionID); + } + + public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) + { + // Try the hyperlink collection + if (m_HyperlinkRegions.ContainsKey(regionID)) + return m_HyperlinkRegions[regionID]; + + // Try the foreign users home collection + if (m_knownRegions.ContainsKey(regionID)) + return m_knownRegions[regionID]; + + // Finally, try the normal route + return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); + } + + public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) + { + int snapX = (int) (x / Constants.RegionSize) * (int)Constants.RegionSize; + int snapY = (int) (y / Constants.RegionSize) * (int)Constants.RegionSize; + // Try the hyperlink collection + foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + { + if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) + return r; + } + + // Try the foreign users home collection + foreach (SimpleRegionInfo r in m_knownRegions.Values) + { + if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) + return r; + } + + // Finally, try the normal route + return m_GridServiceConnector.GetRegionByPosition(scopeID, x, y); + } + + public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) + { + // Try normal grid first + SimpleRegionInfo region = m_GridServiceConnector.GetRegionByName(scopeID, regionName); + if (region != null) + return region; + + // !!! Commenting until region name exists + //// Try the hyperlink collection + //foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + //{ + // if (r.RegionName == regionName) + // return r; + //} + + //// Try the foreign users home collection + //foreach (SimpleRegionInfo r in m_knownRegions.Values) + //{ + // if (r.RegionName == regionName) + // return r; + //} + return null; + } + + public List GetRegionsByName(UUID scopeID, string name, int maxNumber) + { + List rinfos = new List(); + + // Commenting until regionname exists + //foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + // if ((r.RegionName != null) && r.RegionName.StartsWith(name)) + // rinfos.Add(r); + + rinfos.AddRange(m_GridServiceConnector.GetRegionsByName(scopeID, name, maxNumber)); + return rinfos; + } + + public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) + { + int snapXmin = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize; + int snapXmax = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize; + int snapYmin = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize; + int snapYmax = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize; + + List rinfos = new List(); + foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + if ((r.RegionLocX > snapXmin) && (r.RegionLocX < snapYmax) && + (r.RegionLocY > snapYmin) && (r.RegionLocY < snapYmax)) + rinfos.Add(r); + + rinfos.AddRange(m_GridServiceConnector.GetRegionRange(scopeID, xmin, xmax, ymin, ymax)); + + return rinfos; + } + + #endregion + + + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 74ece2e..3f29401 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs @@ -50,6 +50,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private bool m_Enabled = false; + public LocalGridServicesConnector(IConfigSource source) + { + InitialiseService(source); + } + #region ISharedRegionModule public Type ReplaceableInterface @@ -70,38 +75,43 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid string name = moduleConfig.GetString("GridServices", ""); if (name == Name) { - IConfig assetConfig = source.Configs["GridService"]; - if (assetConfig == null) - { - m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); - return; - } - - string serviceDll = assetConfig.GetString("LocalServiceModule", - String.Empty); - - if (serviceDll == String.Empty) - { - m_log.Error("[GRID CONNECTOR]: No LocalServiceModule named in section GridService"); - return; - } - - Object[] args = new Object[] { source }; - m_GridService = - ServerUtils.LoadPlugin(serviceDll, - args); - - if (m_GridService == null) - { - m_log.Error("[GRID CONNECTOR]: Can't load asset service"); - return; - } + InitialiseService(source); m_Enabled = true; - m_log.Info("[GRID CONNECTOR]: Local grid connector enabled"); + m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled"); } } } + private void InitialiseService(IConfigSource source) + { + IConfig assetConfig = source.Configs["GridService"]; + if (assetConfig == null) + { + m_log.Error("[LOCAL GRID CONNECTOR]: GridService missing from OpenSim.ini"); + return; + } + + string serviceDll = assetConfig.GetString("LocalServiceModule", + String.Empty); + + if (serviceDll == String.Empty) + { + m_log.Error("[LOCAL GRID CONNECTOR]: No LocalServiceModule named in section GridService"); + return; + } + + Object[] args = new Object[] { source }; + m_GridService = + ServerUtils.LoadPlugin(serviceDll, + args); + + if (m_GridService == null) + { + m_log.Error("[LOCAL GRID CONNECTOR]: Can't load asset service"); + return; + } + } + public void PostInitialise() { } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs index b0cfc9c..22b1015 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs @@ -47,6 +47,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private bool m_Enabled = false; + public RemoteGridServicesConnector(IConfigSource source) + { + InitialiseService(source); + } + + #region ISharedRegionmodule + public Type ReplaceableInterface { get { return null; } @@ -65,22 +72,25 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid string name = moduleConfig.GetString("GridServices", ""); if (name == Name) { - IConfig gridConfig = source.Configs["GridService"]; - if (gridConfig == null) - { - m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); - return; - } - + InitialiseService(source); m_Enabled = true; - - base.Initialise(source); - - m_log.Info("[GRID CONNECTOR]: Remote grid enabled"); + m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled"); } } } + private void InitialiseService(IConfigSource source) + { + IConfig gridConfig = source.Configs["GridService"]; + if (gridConfig == null) + { + m_log.Error("[REMOTE GRID CONNECTOR]: GridService missing from OpenSim.ini"); + return; + } + + base.Initialise(source); + } + public void PostInitialise() { } @@ -104,5 +114,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void RegionLoaded(Scene scene) { } + + #endregion } } -- cgit v1.1 From ffd30b8ac31bc408316079ba86076bf9e984a8be Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 22 Sep 2009 14:46:05 -0700 Subject: Moved RegionName from RegionInfo to SimpleRegionInfo. --- .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 83 +++++++++++++++------- 1 file changed, 59 insertions(+), 24 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index b7e3213..e3cb05c 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -63,6 +63,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid // This is key-ed on agent ID protected Dictionary m_knownRegions = new Dictionary(); + protected Dictionary m_HyperlinkHandles = new Dictionary(); + #region ISharedRegionModule public Type ReplaceableInterface @@ -160,10 +162,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (regionInfo.RegionID.Equals(UUID.Zero)) { m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort); - regionInfo.RegionID = m_HypergridServiceConnector.LinkRegion(regionInfo); + ulong regionHandle = 0; + regionInfo.RegionID = m_HypergridServiceConnector.LinkRegion(regionInfo, out regionHandle); if (!regionInfo.RegionID.Equals(UUID.Zero)) { - m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); + AddHyperlinkRegion(regionInfo, regionHandle); m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID); // Try get the map image @@ -186,15 +189,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid // Try the hyperlink collection if (m_HyperlinkRegions.ContainsKey(regionID)) { - m_HyperlinkRegions.Remove(regionID); + RemoveHyperlinkRegion(regionID); return true; } // Try the foreign users home collection - if (m_knownRegions.ContainsKey(regionID)) - { - m_knownRegions.Remove(regionID); - return true; - } + + foreach (SimpleRegionInfo r in m_knownRegions.Values) + if (r.RegionID == regionID) + { + RemoveHyperlinkHomeRegion(regionID); + return true; + } + // Finally, try the normal route return m_GridServiceConnector.DeregisterRegion(regionID); } @@ -213,8 +219,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return m_HyperlinkRegions[regionID]; // Try the foreign users home collection - if (m_knownRegions.ContainsKey(regionID)) - return m_knownRegions[regionID]; + foreach (SimpleRegionInfo r in m_knownRegions.Values) + if (r.RegionID == regionID) + return m_knownRegions[regionID]; // Finally, try the normal route return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); @@ -249,20 +256,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (region != null) return region; - // !!! Commenting until region name exists - //// Try the hyperlink collection - //foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) - //{ - // if (r.RegionName == regionName) - // return r; - //} - - //// Try the foreign users home collection - //foreach (SimpleRegionInfo r in m_knownRegions.Values) - //{ - // if (r.RegionName == regionName) - // return r; - //} + // Try the hyperlink collection + foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + { + if (r.RegionName == regionName) + return r; + } + + // Try the foreign users home collection + foreach (SimpleRegionInfo r in m_knownRegions.Values) + { + if (r.RegionName == regionName) + return r; + } return null; } @@ -299,6 +305,35 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid #endregion + private void AddHyperlinkRegion(SimpleRegionInfo regionInfo, ulong regionHandle) + { + m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); + m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); + } + + private void RemoveHyperlinkRegion(UUID regionID) + { + m_HyperlinkRegions.Remove(regionID); + m_HyperlinkHandles.Remove(regionID); + } + + private void AddHyperlinkHomeRegion(UUID userID, SimpleRegionInfo regionInfo, ulong regionHandle) + { + m_knownRegions.Add(userID, regionInfo); + m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); + } + + private void RemoveHyperlinkHomeRegion(UUID regionID) + { + foreach (KeyValuePair kvp in m_knownRegions) + { + if (kvp.Value.RegionID == regionID) + { + m_knownRegions.Remove(kvp.Key); + } + } + m_HyperlinkHandles.Remove(regionID); + } } } -- cgit v1.1 From 882d2c9cc399c4c7d1809702104ce94c9c2c7b17 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 22 Sep 2009 20:25:00 -0700 Subject: Added hg console commands to the module. Added the IN connector module for link-region and corresponding handler to be used in the regions only. No service as such is needed. This will replace the current link-region machinery. Compiles but not tested. --- .../ServiceConnectorsOut/Grid/HGCommands.cs | 295 +++++++++++++++++++++ .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 213 ++++++++++++++- .../Grid/RemoteGridServiceConnector.cs | 64 ++++- 3 files changed, 567 insertions(+), 5 deletions(-) create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs new file mode 100644 index 0000000..eee3a6c --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs @@ -0,0 +1,295 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Xml; +using log4net; +using Nini.Config; +using OpenSim.Framework; +//using OpenSim.Framework.Communications; +using OpenSim.Framework.Console; +using OpenSim.Region.Framework; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Framework.Scenes.Hypergrid; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid +{ + public class HGCommands + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private HGGridConnector m_HGGridConnector; + private Scene m_scene; + + private static uint m_autoMappingX = 0; + private static uint m_autoMappingY = 0; + private static bool m_enableAutoMapping = false; + + public HGCommands(HGGridConnector hgConnector, Scene scene) + { + m_HGGridConnector = hgConnector; + m_scene = scene; + } + + //public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager, CommunicationsManager m_commsManager, + // StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version) + //{ + // HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager, HGServices); + + // return + // new HGScene( + // regionInfo, circuitManager, m_commsManager, sceneGridService, storageManager, + // m_moduleLoader, false, m_configSettings.PhysicalPrim, + // m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version); + //} + + public void RunCommand(string module, string[] cmdparams) + { + List args = new List(cmdparams); + if (args.Count < 1) + return; + + string command = args[0]; + args.RemoveAt(0); + + cmdparams = args.ToArray(); + + RunHGCommand(command, cmdparams); + + } + + private void RunHGCommand(string command, string[] cmdparams) + { + if (command.Equals("link-mapping")) + { + if (cmdparams.Length == 2) + { + try + { + m_autoMappingX = Convert.ToUInt32(cmdparams[0]); + m_autoMappingY = Convert.ToUInt32(cmdparams[1]); + m_enableAutoMapping = true; + } + catch (Exception) + { + m_autoMappingX = 0; + m_autoMappingY = 0; + m_enableAutoMapping = false; + } + } + } + else if (command.Equals("link-region")) + { + if (cmdparams.Length < 3) + { + if ((cmdparams.Length == 1) || (cmdparams.Length == 2)) + { + LoadXmlLinkFile(cmdparams); + } + else + { + LinkRegionCmdUsage(); + } + return; + } + + if (cmdparams[2].Contains(":")) + { + // New format + uint xloc, yloc; + string mapName; + try + { + xloc = Convert.ToUInt32(cmdparams[0]); + yloc = Convert.ToUInt32(cmdparams[1]); + mapName = cmdparams[2]; + if (cmdparams.Length > 3) + for (int i = 3; i < cmdparams.Length; i++) + mapName += " " + cmdparams[i]; + + m_log.Info(">> MapName: " + mapName); + //internalPort = Convert.ToUInt32(cmdparams[4]); + //remotingPort = Convert.ToUInt32(cmdparams[5]); + } + catch (Exception e) + { + m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message); + LinkRegionCmdUsage(); + return; + } + + m_HGGridConnector.TryLinkRegionToCoords(m_scene, null, mapName, xloc, yloc); + } + else + { + // old format + SimpleRegionInfo regInfo; + uint xloc, yloc; + uint externalPort; + string externalHostName; + try + { + xloc = Convert.ToUInt32(cmdparams[0]); + yloc = Convert.ToUInt32(cmdparams[1]); + externalPort = Convert.ToUInt32(cmdparams[3]); + externalHostName = cmdparams[2]; + //internalPort = Convert.ToUInt32(cmdparams[4]); + //remotingPort = Convert.ToUInt32(cmdparams[5]); + } + catch (Exception e) + { + m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message); + LinkRegionCmdUsage(); + return; + } + + //if (TryCreateLink(xloc, yloc, externalPort, externalHostName, out regInfo)) + if (m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo)) + { + if (cmdparams.Length >= 5) + { + regInfo.RegionName = ""; + for (int i = 4; i < cmdparams.Length; i++) + regInfo.RegionName += cmdparams[i] + " "; + } + } + } + return; + } + else if (command.Equals("unlink-region")) + { + if (cmdparams.Length < 1) + { + UnlinkRegionCmdUsage(); + return; + } + if (m_HGGridConnector.TryUnlinkRegion(m_scene, cmdparams[0])) + m_log.InfoFormat("[HGrid]: Successfully unlinked {0}", cmdparams[0]); + else + m_log.InfoFormat("[HGrid]: Unable to unlink {0}, region not found", cmdparams[0]); + } + } + + private void LoadXmlLinkFile(string[] cmdparams) + { + //use http://www.hgurl.com/hypergrid.xml for test + try + { + XmlReader r = XmlReader.Create(cmdparams[0]); + XmlConfigSource cs = new XmlConfigSource(r); + string[] excludeSections = null; + + if (cmdparams.Length == 2) + { + if (cmdparams[1].ToLower().StartsWith("excludelist:")) + { + string excludeString = cmdparams[1].ToLower(); + excludeString = excludeString.Remove(0, 12); + char[] splitter = { ';' }; + + excludeSections = excludeString.Split(splitter); + } + } + + for (int i = 0; i < cs.Configs.Count; i++) + { + bool skip = false; + if ((excludeSections != null) && (excludeSections.Length > 0)) + { + for (int n = 0; n < excludeSections.Length; n++) + { + if (excludeSections[n] == cs.Configs[i].Name.ToLower()) + { + skip = true; + break; + } + } + } + if (!skip) + { + ReadLinkFromConfig(cs.Configs[i]); + } + } + } + catch (Exception e) + { + m_log.Error(e.ToString()); + } + } + + + private void ReadLinkFromConfig(IConfig config) + { + SimpleRegionInfo regInfo; + uint xloc, yloc; + uint externalPort; + string externalHostName; + uint realXLoc, realYLoc; + + xloc = Convert.ToUInt32(config.GetString("xloc", "0")); + yloc = Convert.ToUInt32(config.GetString("yloc", "0")); + externalPort = Convert.ToUInt32(config.GetString("externalPort", "0")); + externalHostName = config.GetString("externalHostName", ""); + realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0")); + realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0")); + + if (m_enableAutoMapping) + { + xloc = (uint)((xloc % 100) + m_autoMappingX); + yloc = (uint)((yloc % 100) + m_autoMappingY); + } + + if (((realXLoc == 0) && (realYLoc == 0)) || + (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) && + ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896)))) + { + if ( + m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, + externalHostName, out regInfo)) + { + regInfo.RegionName = config.GetString("localName", ""); + } + } + } + + + private void LinkRegionCmdUsage() + { + m_log.Info("Usage: link-region :[:]"); + m_log.Info("Usage: link-region []"); + m_log.Info("Usage: link-region []"); + } + + private void UnlinkRegionCmdUsage() + { + m_log.Info("Usage: unlink-region :"); + m_log.Info("Usage: unlink-region "); + } + + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index e3cb05c..7aeb761 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -27,14 +27,18 @@ using System; using System.Collections.Generic; +using System.Net; using System.Reflection; +using System.Xml; using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Framework.Scenes.Hypergrid; using OpenSim.Services.Interfaces; using OpenSim.Server.Base; using OpenSim.Services.Connectors.Grid; +using OpenSim.Framework.Console; using OpenMetaverse; using log4net; @@ -94,7 +98,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid InitialiseConnectorModule(source); - + m_Enabled = true; m_log.Info("[HGGRID CONNECTOR]: HG grid enabled"); } @@ -137,6 +141,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return; scene.RegisterModuleInterface(this); + } public void RemoveRegion(Scene scene) @@ -145,11 +150,25 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void RegionLoaded(Scene scene) { - if (m_Enabled && !m_Initialized) + if (!m_Enabled) + return; + + if (!m_Initialized) { m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); m_Initialized = true; } + + HGCommands hgCommands = new HGCommands(this, scene); + scene.AddCommand("HG", "link-region", + "link-region :[:] ", + "Link a hypergrid region", hgCommands.RunCommand); + scene.AddCommand("HG", "unlink-region", + "unlink-region or : ", + "Unlink a hypergrid region", hgCommands.RunCommand); + scene.AddCommand("HG", "link-mapping", "link-mapping [ ] ", + "Set local coordinate to map HG regions to", hgCommands.RunCommand); + } #endregion @@ -305,6 +324,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid #endregion + #region Auxiliary + private void AddHyperlinkRegion(SimpleRegionInfo regionInfo, ulong regionHandle) { m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); @@ -334,6 +355,194 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } m_HyperlinkHandles.Remove(regionID); } + #endregion + + #region Hyperlinks + + private static Random random = new Random(); + + public SimpleRegionInfo TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, uint xloc, uint yloc) + { + string host = "127.0.0.1"; + string portstr; + string regionName = ""; + uint port = 9000; + string[] parts = mapName.Split(new char[] { ':' }); + if (parts.Length >= 1) + { + host = parts[0]; + } + if (parts.Length >= 2) + { + portstr = parts[1]; + if (!UInt32.TryParse(portstr, out port)) + regionName = parts[1]; + } + // always take the last one + if (parts.Length >= 3) + { + regionName = parts[2]; + } + + // Sanity check. Don't ever link to this sim. + IPAddress ipaddr = null; + try + { + ipaddr = Util.GetHostFromDNS(host); + } + catch { } + + if ((ipaddr != null) && + !((m_scene.RegionInfo.ExternalEndPoint.Address.Equals(ipaddr)) && (m_scene.RegionInfo.HttpPort == port))) + { + SimpleRegionInfo regInfo; + bool success = TryCreateLink(m_scene, client, xloc, yloc, regionName, port, host, out regInfo); + if (success) + { + regInfo.RegionName = mapName; + return regInfo; + } + } + + return null; + } + + public SimpleRegionInfo TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) + { + uint xloc = (uint)(random.Next(0, Int16.MaxValue)); + return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); + } + + public bool TryCreateLink(Scene m_scene, IClientAPI client, uint xloc, uint yloc, + string externalRegionName, uint externalPort, string externalHostName, out SimpleRegionInfo regInfo) + { + m_log.DebugFormat("[HGrid]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc); + + regInfo = new SimpleRegionInfo(); + regInfo.RegionName = externalRegionName; + regInfo.HttpPort = externalPort; + regInfo.ExternalHostName = externalHostName; + regInfo.RegionLocX = xloc; + regInfo.RegionLocY = yloc; + + try + { + regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0); + } + catch (Exception e) + { + m_log.Warn("[HGrid]: Wrong format for link-region: " + e.Message); + return false; + } + + // Finally, link it + try + { + RegisterRegion(UUID.Zero, regInfo); + } + catch (Exception e) + { + m_log.Warn("[HGrid]: Unable to link region: " + e.Message); + return false; + } + + uint x, y; + if (!Check4096(m_scene, regInfo, out x, out y)) + { + DeregisterRegion(regInfo.RegionID); + if (client != null) + client.SendAlertMessage("Region is too far (" + x + ", " + y + ")"); + m_log.Info("[HGrid]: Unable to link, region is too far (" + x + ", " + y + ")"); + return false; + } + + if (!CheckCoords(m_scene.RegionInfo.RegionLocX, m_scene.RegionInfo.RegionLocY, x, y)) + { + DeregisterRegion(regInfo.RegionID); + if (client != null) + client.SendAlertMessage("Region has incompatible coordinates (" + x + ", " + y + ")"); + m_log.Info("[HGrid]: Unable to link, region has incompatible coordinates (" + x + ", " + y + ")"); + return false; + } + + m_log.Debug("[HGrid]: link region succeeded"); + return true; + } + + public bool TryUnlinkRegion(Scene m_scene, string mapName) + { + SimpleRegionInfo regInfo = null; + if (mapName.Contains(":")) + { + string host = "127.0.0.1"; + //string portstr; + //string regionName = ""; + uint port = 9000; + string[] parts = mapName.Split(new char[] { ':' }); + if (parts.Length >= 1) + { + host = parts[0]; + } + // if (parts.Length >= 2) + // { + // portstr = parts[1]; + // if (!UInt32.TryParse(portstr, out port)) + // regionName = parts[1]; + // } + // always take the last one + // if (parts.Length >= 3) + // { + // regionName = parts[2]; + // } + foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + if (host.Equals(r.ExternalHostName) && (port == r.HttpPort)) + regInfo = r; + } + else + { + foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + if (r.RegionName.Equals(mapName)) + regInfo = r; + } + if (regInfo != null) + { + return DeregisterRegion(regInfo.RegionID); + } + else + { + m_log.InfoFormat("[HGrid]: Region {0} not found", mapName); + return false; + } + } + + /// + /// Cope with this viewer limitation. + /// + /// + /// + public bool Check4096(Scene m_scene, SimpleRegionInfo regInfo, out uint x, out uint y) + { + ulong realHandle = m_HyperlinkHandles[regInfo.RegionID]; + Utils.LongToUInts(realHandle, out x, out y); + x = x / Constants.RegionSize; + y = y / Constants.RegionSize; + + if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - (int)x) >= 4096) || + (Math.Abs((int)m_scene.RegionInfo.RegionLocY - (int)y) >= 4096)) + { + return false; + } + return true; + } + + public bool CheckCoords(uint thisx, uint thisy, uint x, uint y) + { + if ((thisx == x) && (thisy == y)) + return false; + return true; + } + + #endregion } } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs index 22b1015..8526653 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs @@ -30,6 +30,8 @@ using System; using System.Collections.Generic; using System.Reflection; using Nini.Config; +using OpenMetaverse; + using OpenSim.Framework; using OpenSim.Services.Connectors; using OpenSim.Region.Framework.Interfaces; @@ -47,9 +49,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private bool m_Enabled = false; + private IGridService m_LocalGridService; + public RemoteGridServicesConnector(IConfigSource source) { - InitialiseService(source); + InitialiseServices(source); } #region ISharedRegionmodule @@ -72,14 +76,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid string name = moduleConfig.GetString("GridServices", ""); if (name == Name) { - InitialiseService(source); + InitialiseServices(source); m_Enabled = true; m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled"); } } } - private void InitialiseService(IConfigSource source) + private void InitialiseServices(IConfigSource source) { IConfig gridConfig = source.Configs["GridService"]; if (gridConfig == null) @@ -89,6 +93,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } base.Initialise(source); + + m_LocalGridService = new LocalGridServicesConnector(source); } public void PostInitialise() @@ -116,5 +122,57 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } #endregion + + #region IGridService + + public override bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) + { + if (m_LocalGridService.RegisterRegion(scopeID, regionInfo)) + return base.RegisterRegion(scopeID, regionInfo); + + return false; + } + + public override bool DeregisterRegion(UUID regionID) + { + if (m_LocalGridService.DeregisterRegion(regionID)) + return base.DeregisterRegion(regionID); + + return false; + } + + // Let's not override GetNeighbours -- let's get them all from the grid server + + public override SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) + { + SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID); + if (rinfo == null) + rinfo = base.GetRegionByUUID(scopeID, regionID); + + return rinfo; + } + + public override SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) + { + SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); + if (rinfo == null) + rinfo = base.GetRegionByPosition(scopeID, x, y); + + return rinfo; + } + + public override SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) + { + SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName); + if (rinfo == null) + rinfo = base.GetRegionByName(scopeID, regionName); + + return rinfo; + } + + // Let's not override GetRegionsByName -- let's get them all from the grid server + // Let's not override GetRegionRange -- let's get them all from the grid server + + #endregion } } -- cgit v1.1 From 35deff7ec4df6156abccdbeed83b14a6083e28f9 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 23 Sep 2009 09:27:01 -0700 Subject: Modules active. Tested HGGridConnector in standalone only for now. Modules commands work. --- .../ServiceConnectorsOut/Grid/HGCommands.cs | 6 ++--- .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 28 +++++++++++++++------- .../Grid/LocalGridServiceConnector.cs | 4 ++++ .../Grid/RemoteGridServiceConnector.cs | 4 ++++ 4 files changed, 30 insertions(+), 12 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs index eee3a6c..2a862d4 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs @@ -85,7 +85,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private void RunHGCommand(string command, string[] cmdparams) { - if (command.Equals("link-mapping")) + if (command.Equals("linkk-mapping")) { if (cmdparams.Length == 2) { @@ -103,7 +103,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } } } - else if (command.Equals("link-region")) + else if (command.Equals("linkk-region")) { if (cmdparams.Length < 3) { @@ -181,7 +181,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } return; } - else if (command.Equals("unlink-region")) + else if (command.Equals("unlinkk-region")) { if (cmdparams.Length < 1) { diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index 7aeb761..c6ade15 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -156,18 +156,27 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (!m_Initialized) { m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); + HGCommands hgCommands = new HGCommands(this, scene); + MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-region", + "link-region :[:] ", + "Link a hypergrid region", hgCommands.RunCommand); + MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlinkk-region", + "unlink-region or : ", + "Unlink a hypergrid region", hgCommands.RunCommand); + MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-mapping", "link-mapping [ ] ", + "Set local coordinate to map HG regions to", hgCommands.RunCommand); m_Initialized = true; } - HGCommands hgCommands = new HGCommands(this, scene); - scene.AddCommand("HG", "link-region", - "link-region :[:] ", - "Link a hypergrid region", hgCommands.RunCommand); - scene.AddCommand("HG", "unlink-region", - "unlink-region or : ", - "Unlink a hypergrid region", hgCommands.RunCommand); - scene.AddCommand("HG", "link-mapping", "link-mapping [ ] ", - "Set local coordinate to map HG regions to", hgCommands.RunCommand); + + //scene.AddCommand("HGGridServicesConnector", "linkk-region", + // "link-region :[:] ", + // "Link a hypergrid region", hgCommands.RunCommand); + //scene.AddCommand("HGGridServicesConnector", "unlinkk-region", + // "unlink-region or : ", + // "Unlink a hypergrid region", hgCommands.RunCommand); + //scene.AddCommand("HGGridServicesConnector", "linkk-mapping", "link-mapping [ ] ", + // "Set local coordinate to map HG regions to", hgCommands.RunCommand); } @@ -407,6 +416,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return null; } + // From the map search and secondlife://blah public SimpleRegionInfo TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) { uint xloc = (uint)(random.Next(0, Int16.MaxValue)); diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 3f29401..c1b7235 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs @@ -50,6 +50,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private bool m_Enabled = false; + public LocalGridServicesConnector() + { + } + public LocalGridServicesConnector(IConfigSource source) { InitialiseService(source); diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs index 8526653..4303fa8 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs @@ -51,6 +51,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private IGridService m_LocalGridService; + public RemoteGridServicesConnector() + { + } + public RemoteGridServicesConnector(IConfigSource source) { InitialiseServices(source); -- cgit v1.1 From 67276589c883fe1a74d8d52057db1431d637dade Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 23 Sep 2009 17:20:07 -0700 Subject: Changed IGridService to use the new GridRegion data structure instead of old SimpleRegionInfo. Added grid configs to standalones. --- .../ServiceConnectorsOut/Grid/HGCommands.cs | 36 ++++++---- .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 82 +++++++++++----------- .../Grid/LocalGridServiceConnector.cs | 18 ++--- .../Grid/RemoteGridServiceConnector.cs | 15 ++-- 4 files changed, 82 insertions(+), 69 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs index 2a862d4..36915ef 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs @@ -37,6 +37,7 @@ using OpenSim.Framework.Console; using OpenSim.Region.Framework; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes.Hypergrid; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { @@ -121,12 +122,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (cmdparams[2].Contains(":")) { // New format - uint xloc, yloc; + int xloc, yloc; string mapName; try { - xloc = Convert.ToUInt32(cmdparams[0]); - yloc = Convert.ToUInt32(cmdparams[1]); + xloc = Convert.ToInt32(cmdparams[0]); + yloc = Convert.ToInt32(cmdparams[1]); mapName = cmdparams[2]; if (cmdparams.Length > 3) for (int i = 3; i < cmdparams.Length; i++) @@ -143,19 +144,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return; } + // Convert cell coordinates given by the user to meters + xloc = xloc * (int)Constants.RegionSize; + yloc = yloc * (int)Constants.RegionSize; m_HGGridConnector.TryLinkRegionToCoords(m_scene, null, mapName, xloc, yloc); } else { // old format - SimpleRegionInfo regInfo; - uint xloc, yloc; + GridRegion regInfo; + int xloc, yloc; uint externalPort; string externalHostName; try { - xloc = Convert.ToUInt32(cmdparams[0]); - yloc = Convert.ToUInt32(cmdparams[1]); + xloc = Convert.ToInt32(cmdparams[0]); + yloc = Convert.ToInt32(cmdparams[1]); externalPort = Convert.ToUInt32(cmdparams[3]); externalHostName = cmdparams[2]; //internalPort = Convert.ToUInt32(cmdparams[4]); @@ -168,7 +172,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return; } - //if (TryCreateLink(xloc, yloc, externalPort, externalHostName, out regInfo)) + // Convert cell coordinates given by the user to meters + xloc = xloc * (int)Constants.RegionSize; + yloc = yloc * (int)Constants.RegionSize; if (m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo)) { if (cmdparams.Length >= 5) @@ -245,14 +251,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private void ReadLinkFromConfig(IConfig config) { - SimpleRegionInfo regInfo; - uint xloc, yloc; + GridRegion regInfo; + int xloc, yloc; uint externalPort; string externalHostName; uint realXLoc, realYLoc; - xloc = Convert.ToUInt32(config.GetString("xloc", "0")); - yloc = Convert.ToUInt32(config.GetString("yloc", "0")); + xloc = Convert.ToInt32(config.GetString("xloc", "0")); + yloc = Convert.ToInt32(config.GetString("yloc", "0")); externalPort = Convert.ToUInt32(config.GetString("externalPort", "0")); externalHostName = config.GetString("externalHostName", ""); realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0")); @@ -260,14 +266,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (m_enableAutoMapping) { - xloc = (uint)((xloc % 100) + m_autoMappingX); - yloc = (uint)((yloc % 100) + m_autoMappingY); + xloc = (int)((xloc % 100) + m_autoMappingX); + yloc = (int)((yloc % 100) + m_autoMappingY); } if (((realXLoc == 0) && (realYLoc == 0)) || (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) && ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896)))) { + xloc = xloc * (int)Constants.RegionSize; + yloc = yloc * (int)Constants.RegionSize; if ( m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo)) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index c6ade15..0c2a835 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -36,6 +36,7 @@ using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes.Hypergrid; using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; using OpenSim.Server.Base; using OpenSim.Services.Connectors.Grid; using OpenSim.Framework.Console; @@ -59,13 +60,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private HypergridServiceConnector m_HypergridServiceConnector; // Hyperlink regions are hyperlinks on the map - protected Dictionary m_HyperlinkRegions = new Dictionary(); + protected Dictionary m_HyperlinkRegions = new Dictionary(); // Known regions are home regions of visiting foreign users. // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when // the visitor goes away. They are mapped to X=0 on the map. // This is key-ed on agent ID - protected Dictionary m_knownRegions = new Dictionary(); + protected Dictionary m_knownRegions = new Dictionary(); protected Dictionary m_HyperlinkHandles = new Dictionary(); @@ -184,7 +185,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid #region IGridService - public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) + public bool RegisterRegion(UUID scopeID, GridRegion regionInfo) { // Region doesn't exist here. Trying to link remote region if (regionInfo.RegionID.Equals(UUID.Zero)) @@ -222,7 +223,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } // Try the foreign users home collection - foreach (SimpleRegionInfo r in m_knownRegions.Values) + foreach (GridRegion r in m_knownRegions.Values) if (r.RegionID == regionID) { RemoveHyperlinkHomeRegion(regionID); @@ -233,21 +234,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return m_GridServiceConnector.DeregisterRegion(regionID); } - public List GetNeighbours(UUID scopeID, UUID regionID) + public List GetNeighbours(UUID scopeID, UUID regionID) { // No serving neighbours on hyperliked regions. // Just the regular regions. return m_GridServiceConnector.GetNeighbours(scopeID, regionID); } - public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) + public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) { // Try the hyperlink collection if (m_HyperlinkRegions.ContainsKey(regionID)) return m_HyperlinkRegions[regionID]; // Try the foreign users home collection - foreach (SimpleRegionInfo r in m_knownRegions.Values) + foreach (GridRegion r in m_knownRegions.Values) if (r.RegionID == regionID) return m_knownRegions[regionID]; @@ -255,19 +256,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); } - public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) + public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { int snapX = (int) (x / Constants.RegionSize) * (int)Constants.RegionSize; int snapY = (int) (y / Constants.RegionSize) * (int)Constants.RegionSize; // Try the hyperlink collection - foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + foreach (GridRegion r in m_HyperlinkRegions.Values) { if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) return r; } // Try the foreign users home collection - foreach (SimpleRegionInfo r in m_knownRegions.Values) + foreach (GridRegion r in m_knownRegions.Values) { if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) return r; @@ -277,22 +278,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return m_GridServiceConnector.GetRegionByPosition(scopeID, x, y); } - public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) + public GridRegion GetRegionByName(UUID scopeID, string regionName) { // Try normal grid first - SimpleRegionInfo region = m_GridServiceConnector.GetRegionByName(scopeID, regionName); + GridRegion region = m_GridServiceConnector.GetRegionByName(scopeID, regionName); if (region != null) return region; // Try the hyperlink collection - foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + foreach (GridRegion r in m_HyperlinkRegions.Values) { if (r.RegionName == regionName) return r; } // Try the foreign users home collection - foreach (SimpleRegionInfo r in m_knownRegions.Values) + foreach (GridRegion r in m_knownRegions.Values) { if (r.RegionName == regionName) return r; @@ -300,9 +301,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return null; } - public List GetRegionsByName(UUID scopeID, string name, int maxNumber) + public List GetRegionsByName(UUID scopeID, string name, int maxNumber) { - List rinfos = new List(); + List rinfos = new List(); // Commenting until regionname exists //foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) @@ -313,15 +314,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return rinfos; } - public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) + public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) { int snapXmin = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize; int snapXmax = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize; int snapYmin = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize; int snapYmax = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize; - List rinfos = new List(); - foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + List rinfos = new List(); + foreach (GridRegion r in m_HyperlinkRegions.Values) if ((r.RegionLocX > snapXmin) && (r.RegionLocX < snapYmax) && (r.RegionLocY > snapYmin) && (r.RegionLocY < snapYmax)) rinfos.Add(r); @@ -335,7 +336,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid #region Auxiliary - private void AddHyperlinkRegion(SimpleRegionInfo regionInfo, ulong regionHandle) + private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) { m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); @@ -347,7 +348,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid m_HyperlinkHandles.Remove(regionID); } - private void AddHyperlinkHomeRegion(UUID userID, SimpleRegionInfo regionInfo, ulong regionHandle) + private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle) { m_knownRegions.Add(userID, regionInfo); m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); @@ -355,7 +356,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private void RemoveHyperlinkHomeRegion(UUID regionID) { - foreach (KeyValuePair kvp in m_knownRegions) + foreach (KeyValuePair kvp in m_knownRegions) { if (kvp.Value.RegionID == regionID) { @@ -370,7 +371,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private static Random random = new Random(); - public SimpleRegionInfo TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, uint xloc, uint yloc) + public GridRegion TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, int xloc, int yloc) { string host = "127.0.0.1"; string portstr; @@ -404,7 +405,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if ((ipaddr != null) && !((m_scene.RegionInfo.ExternalEndPoint.Address.Equals(ipaddr)) && (m_scene.RegionInfo.HttpPort == port))) { - SimpleRegionInfo regInfo; + GridRegion regInfo; bool success = TryCreateLink(m_scene, client, xloc, yloc, regionName, port, host, out regInfo); if (success) { @@ -417,18 +418,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } // From the map search and secondlife://blah - public SimpleRegionInfo TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) + public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) { - uint xloc = (uint)(random.Next(0, Int16.MaxValue)); + int xloc = random.Next(0, Int16.MaxValue); return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); } - public bool TryCreateLink(Scene m_scene, IClientAPI client, uint xloc, uint yloc, - string externalRegionName, uint externalPort, string externalHostName, out SimpleRegionInfo regInfo) + public bool TryCreateLink(Scene m_scene, IClientAPI client, int xloc, int yloc, + string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo) { m_log.DebugFormat("[HGrid]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc); - regInfo = new SimpleRegionInfo(); + regInfo = new GridRegion(); regInfo.RegionName = externalRegionName; regInfo.HttpPort = externalPort; regInfo.ExternalHostName = externalHostName; @@ -456,7 +457,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return false; } - uint x, y; + int x, y; if (!Check4096(m_scene, regInfo, out x, out y)) { DeregisterRegion(regInfo.RegionID); @@ -481,7 +482,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public bool TryUnlinkRegion(Scene m_scene, string mapName) { - SimpleRegionInfo regInfo = null; + GridRegion regInfo = null; if (mapName.Contains(":")) { string host = "127.0.0.1"; @@ -504,13 +505,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid // { // regionName = parts[2]; // } - foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + foreach (GridRegion r in m_HyperlinkRegions.Values) if (host.Equals(r.ExternalHostName) && (port == r.HttpPort)) regInfo = r; } else { - foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) + foreach (GridRegion r in m_HyperlinkRegions.Values) if (r.RegionName.Equals(mapName)) regInfo = r; } @@ -530,22 +531,23 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid /// /// /// - public bool Check4096(Scene m_scene, SimpleRegionInfo regInfo, out uint x, out uint y) + public bool Check4096(Scene m_scene, GridRegion regInfo, out int x, out int y) { ulong realHandle = m_HyperlinkHandles[regInfo.RegionID]; - Utils.LongToUInts(realHandle, out x, out y); - x = x / Constants.RegionSize; - y = y / Constants.RegionSize; + uint ux = 0, uy = 0; + Utils.LongToUInts(realHandle, out ux, out uy); + x = (int)(ux / Constants.RegionSize); + y = (int)(uy / Constants.RegionSize); - if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - (int)x) >= 4096) || - (Math.Abs((int)m_scene.RegionInfo.RegionLocY - (int)y) >= 4096)) + if ((Math.Abs((int)(m_scene.RegionInfo.RegionLocX / Constants.RegionSize) - x) >= 4096) || + (Math.Abs((int)(m_scene.RegionInfo.RegionLocY / Constants.RegionSize) - y) >= 4096)) { return false; } return true; } - public bool CheckCoords(uint thisx, uint thisy, uint x, uint y) + public bool CheckCoords(uint thisx, uint thisy, int x, int y) { if ((thisx == x) && (thisy == y)) return false; diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index c1b7235..743d3b9 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs @@ -35,6 +35,7 @@ using OpenSim.Server.Base; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; using OpenMetaverse; namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid @@ -56,6 +57,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public LocalGridServicesConnector(IConfigSource source) { + m_log.Debug("[LOCAL GRID CONNECTOR]: LocalGridServicesConnector instantiated"); InitialiseService(source); } @@ -111,7 +113,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (m_GridService == null) { - m_log.Error("[LOCAL GRID CONNECTOR]: Can't load asset service"); + m_log.Error("[LOCAL GRID CONNECTOR]: Can't load grid service"); return; } } @@ -144,7 +146,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid #region IGridService - public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) + public bool RegisterRegion(UUID scopeID, GridRegion regionInfo) { return m_GridService.RegisterRegion(scopeID, regionInfo); } @@ -154,32 +156,32 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return m_GridService.DeregisterRegion(regionID); } - public List GetNeighbours(UUID scopeID, UUID regionID) + public List GetNeighbours(UUID scopeID, UUID regionID) { return m_GridService.GetNeighbours(scopeID, regionID); } - public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) + public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) { return m_GridService.GetRegionByUUID(scopeID, regionID); } - public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) + public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { return m_GridService.GetRegionByPosition(scopeID, x, y); } - public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) + public GridRegion GetRegionByName(UUID scopeID, string regionName) { return m_GridService.GetRegionByName(scopeID, regionName); } - public List GetRegionsByName(UUID scopeID, string name, int maxNumber) + public List GetRegionsByName(UUID scopeID, string name, int maxNumber) { return m_GridService.GetRegionsByName(scopeID, name, maxNumber); } - public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) + public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) { return m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax); } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs index 4303fa8..91a808b 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs @@ -37,6 +37,7 @@ using OpenSim.Services.Connectors; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { @@ -129,7 +130,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid #region IGridService - public override bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) + public override bool RegisterRegion(UUID scopeID, GridRegion regionInfo) { if (m_LocalGridService.RegisterRegion(scopeID, regionInfo)) return base.RegisterRegion(scopeID, regionInfo); @@ -147,27 +148,27 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid // Let's not override GetNeighbours -- let's get them all from the grid server - public override SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) + public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) { - SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID); + GridRegion rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID); if (rinfo == null) rinfo = base.GetRegionByUUID(scopeID, regionID); return rinfo; } - public override SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) + public override GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { - SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); + GridRegion rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); if (rinfo == null) rinfo = base.GetRegionByPosition(scopeID, x, y); return rinfo; } - public override SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) + public override GridRegion GetRegionByName(UUID scopeID, string regionName) { - SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName); + GridRegion rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName); if (rinfo == null) rinfo = base.GetRegionByName(scopeID, regionName); -- cgit v1.1 From 3c19bd5142479e468aa9841a2177ddd33b46f8f6 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 23 Sep 2009 20:35:16 -0700 Subject: Unit tests for the grid service. Yey! --- .../Grid/Tests/GridConnectorsTests.cs | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs new file mode 100644 index 0000000..8d44249 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs @@ -0,0 +1,122 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Threading; +using log4net.Config; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; +using OpenMetaverse; +using OpenSim.Framework; +using Nini.Config; + +using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid; +using OpenSim.Region.Framework.Scenes; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; +using OpenSim.Tests.Common; +using OpenSim.Tests.Common.Setup; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests +{ + [TestFixture] + public class GridConnectorsTests + { + LocalGridServicesConnector m_LocalConnector; + private void SetUp() + { + IConfigSource config = new IniConfigSource(); + config.AddConfig("Modules"); + config.AddConfig("GridService"); + config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector"); + config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService"); + config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData"); + + m_LocalConnector = new LocalGridServicesConnector(config); + } + + /// + /// Test saving a V0.2 OpenSim Region Archive. + /// + [Test] + public void TestRegisterRegionV0_2() + { + SetUp(); + + // Create 3 regions + GridRegion r1 = new GridRegion(); + r1.RegionName = "Test Region 1"; + r1.RegionID = new UUID(1); + r1.RegionLocX = 1000 * (int)Constants.RegionSize; + r1.RegionLocY = 1000 * (int)Constants.RegionSize; + r1.ExternalHostName = "127.0.0.1"; + r1.HttpPort = 9001; + r1.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); + + GridRegion r2 = new GridRegion(); + r2.RegionName = "Test Region 2"; + r2.RegionID = new UUID(2); + r2.RegionLocX = 1000 * (int)Constants.RegionSize + 1; + r2.RegionLocY = 1000 * (int)Constants.RegionSize; + r2.ExternalHostName = "127.0.0.1"; + r2.HttpPort = 9002; + r2.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); + + GridRegion r3 = new GridRegion(); + r3.RegionName = "Test Region 3"; + r3.RegionID = new UUID(3); + r3.RegionLocX = 1000 * (int)Constants.RegionSize + 5; + r3.RegionLocY = 1000 * (int)Constants.RegionSize; + r3.ExternalHostName = "127.0.0.1"; + r3.HttpPort = 9003; + r3.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); + + m_LocalConnector.RegisterRegion(UUID.Zero, r1); + GridRegion result = m_LocalConnector.GetRegionByName(UUID.Zero, "Test"); + Assert.IsNotNull(result, "Retrieved GetRegionByName is null"); + Assert.That(result.RegionName, Is.EqualTo("Test Region 1"), "Retrieved region's name does not match"); + + result = m_LocalConnector.GetRegionByUUID(UUID.Zero, new UUID(1)); + Assert.IsNotNull(result, "Retrieved GetRegionByUUID is null"); + Assert.That(result.RegionID, Is.EqualTo(new UUID(1)), "Retrieved region's UUID does not match"); + + result = m_LocalConnector.GetRegionByPosition(UUID.Zero, 1000 * (int)Constants.RegionSize, 1000 * (int)Constants.RegionSize); + Assert.IsNotNull(result, "Retrieved GetRegionByPosition is null"); + Assert.That(result.RegionLocX, Is.EqualTo(1000 * (int)Constants.RegionSize), "Retrieved region's position does not match"); + + m_LocalConnector.RegisterRegion(UUID.Zero, r2); + m_LocalConnector.RegisterRegion(UUID.Zero, r3); + + List results = m_LocalConnector.GetNeighbours(UUID.Zero, new UUID(1)); + Assert.IsNotNull(results, "Retrieved neighbours list is null"); + Assert.That(results.Count, Is.EqualTo(1), "Retrieved neighbour collection is greater than expected"); + Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2))); + } + } +} -- cgit v1.1 From fd8fb7735b0eb6150679ccad84b2a32fd5315a38 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 23 Sep 2009 20:39:25 -0700 Subject: First test passes -- regions being registered and retrieved correctly in Data.Null. --- .../ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs index 8d44249..bd3293d 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs @@ -82,7 +82,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests GridRegion r2 = new GridRegion(); r2.RegionName = "Test Region 2"; r2.RegionID = new UUID(2); - r2.RegionLocX = 1000 * (int)Constants.RegionSize + 1; + r2.RegionLocX = 1001 * (int)Constants.RegionSize; r2.RegionLocY = 1000 * (int)Constants.RegionSize; r2.ExternalHostName = "127.0.0.1"; r2.HttpPort = 9002; @@ -91,7 +91,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests GridRegion r3 = new GridRegion(); r3.RegionName = "Test Region 3"; r3.RegionID = new UUID(3); - r3.RegionLocX = 1000 * (int)Constants.RegionSize + 5; + r3.RegionLocX = 1005 * (int)Constants.RegionSize; r3.RegionLocY = 1000 * (int)Constants.RegionSize; r3.ExternalHostName = "127.0.0.1"; r3.HttpPort = 9003; -- cgit v1.1 From 1260c81a9cfc19306e2053a8b066e50c78dbc7c1 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 23 Sep 2009 20:51:04 -0700 Subject: More tests. Seems to be working. Grid connector modules are enabled for standalones only, but nothing in the simulator uses them yet, so it's safe to go in. --- .../ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs index bd3293d..be32d6b 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs @@ -116,7 +116,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests List results = m_LocalConnector.GetNeighbours(UUID.Zero, new UUID(1)); Assert.IsNotNull(results, "Retrieved neighbours list is null"); Assert.That(results.Count, Is.EqualTo(1), "Retrieved neighbour collection is greater than expected"); - Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2))); + Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2)), "Retrieved region's UUID does not match"); + + results = m_LocalConnector.GetRegionsByName(UUID.Zero, "Test", 10); + Assert.IsNotNull(results, "Retrieved GetRegionsByName list is null"); + Assert.That(results.Count, Is.EqualTo(3), "Retrieved neighbour collection is less than expected"); + + results = m_LocalConnector.GetRegionRange(UUID.Zero, 900 * (int)Constants.RegionSize, 1002 * (int)Constants.RegionSize, + 900 * (int)Constants.RegionSize, 1100 * (int)Constants.RegionSize); + Assert.IsNotNull(results, "Retrieved GetRegionRange list is null"); + Assert.That(results.Count, Is.EqualTo(2), "Retrieved neighbour collection is not the number expected"); } } } -- cgit v1.1 From 5757afe7665543e8b3ed4a322a7d6e095dafcdb3 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 26 Sep 2009 07:48:21 -0700 Subject: First pass at the heart surgery for grid services. Compiles and runs minimally. A few bugs to catch now. --- .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index 0c2a835..b5bade6 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -47,7 +47,7 @@ using Nini.Config; namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { - public class HGGridConnector : ISharedRegionModule, IGridService + public class HGGridConnector : ISharedRegionModule, IGridService, IHyperlinkService { private static readonly ILog m_log = LogManager.GetLogger( @@ -142,6 +142,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return; scene.RegisterModuleInterface(this); + scene.RegisterModuleInterface(this); } @@ -367,10 +368,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } #endregion - #region Hyperlinks + #region IHyperlinkService private static Random random = new Random(); + public GridRegion TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, int xloc, int yloc) { string host = "127.0.0.1"; @@ -417,6 +419,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return null; } + // From the map search and secondlife://blah public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) { @@ -554,6 +557,27 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return true; } + public GridRegion TryLinkRegion(IClientAPI client, string regionDescriptor) + { + return TryLinkRegion((Scene)client.Scene, client, regionDescriptor); + } + + public GridRegion GetHyperlinkRegion(ulong handle) + { + foreach (GridRegion r in m_HyperlinkRegions.Values) + if (r.RegionHandle == handle) + return r; + return null; + } + + public ulong FindRegionHandle(ulong handle) + { + foreach (GridRegion r in m_HyperlinkRegions.Values) + if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) + return m_HyperlinkHandles[r.RegionID]; + return 0; + } + #endregion } -- cgit v1.1 From d39e67d5b2ca974e7e2506bcb717ec25ae061e75 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 26 Sep 2009 08:06:14 -0700 Subject: More redirects to HGGridConnector-as-HyperlinkService. --- .../Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index b5bade6..66cde91 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -567,6 +567,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid foreach (GridRegion r in m_HyperlinkRegions.Values) if (r.RegionHandle == handle) return r; + foreach (GridRegion r in m_knownRegions.Values) + if (r.RegionHandle == handle) + return r; return null; } @@ -575,7 +578,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid foreach (GridRegion r in m_HyperlinkRegions.Values) if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) return m_HyperlinkHandles[r.RegionID]; - return 0; + return handle; } #endregion -- cgit v1.1 From dcfd08b8dd57e667db8e0b5900da4648a020160e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 26 Sep 2009 11:01:18 -0700 Subject: Fixed a bug with link-region. --- .../ServiceConnectorsOut/Grid/HGCommands.cs | 6 ++--- .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 31 ++++++---------------- 2 files changed, 11 insertions(+), 26 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs index 36915ef..0974372 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs @@ -86,7 +86,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private void RunHGCommand(string command, string[] cmdparams) { - if (command.Equals("linkk-mapping")) + if (command.Equals("link-mapping")) { if (cmdparams.Length == 2) { @@ -104,7 +104,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } } } - else if (command.Equals("linkk-region")) + else if (command.Equals("link-region")) { if (cmdparams.Length < 3) { @@ -187,7 +187,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } return; } - else if (command.Equals("unlinkk-region")) + else if (command.Equals("unlink-region")) { if (cmdparams.Length < 1) { diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index 66cde91..0bb4206 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -159,27 +159,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); HGCommands hgCommands = new HGCommands(this, scene); - MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-region", + MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-region", "link-region :[:] ", "Link a hypergrid region", hgCommands.RunCommand); - MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlinkk-region", + MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlink-region", "unlink-region or : ", "Unlink a hypergrid region", hgCommands.RunCommand); - MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-mapping", "link-mapping [ ] ", + MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-mapping", "link-mapping [ ] ", "Set local coordinate to map HG regions to", hgCommands.RunCommand); m_Initialized = true; } - - - //scene.AddCommand("HGGridServicesConnector", "linkk-region", - // "link-region :[:] ", - // "Link a hypergrid region", hgCommands.RunCommand); - //scene.AddCommand("HGGridServicesConnector", "unlinkk-region", - // "unlink-region or : ", - // "Unlink a hypergrid region", hgCommands.RunCommand); - //scene.AddCommand("HGGridServicesConnector", "linkk-mapping", "link-mapping [ ] ", - // "Set local coordinate to map HG regions to", hgCommands.RunCommand); - } #endregion @@ -450,15 +439,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } // Finally, link it - try - { - RegisterRegion(UUID.Zero, regInfo); - } - catch (Exception e) - { - m_log.Warn("[HGrid]: Unable to link region: " + e.Message); - return false; - } + if (!RegisterRegion(UUID.Zero, regInfo)) + { + m_log.Warn("[HGrid]: Unable to link region"); + return false; + } int x, y; if (!Check4096(m_scene, regInfo, out x, out y)) -- cgit v1.1 From f4bf581b96347b8d7f115eca74fa84a644eb729c Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 26 Sep 2009 21:00:51 -0700 Subject: Moved all HG1 operations to HGGridConnector.cs and HypergridServerConnector.cs/HypergridServiceConnector.cs, away from Region.Communications and HGNetworkServersInfo. Fixed small bugs with hyperlinked regions' map positions. --- .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 227 ++++++++++++++++++++- 1 file changed, 221 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index 0bb4206..52db400 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -31,6 +31,7 @@ using System.Net; using System.Reflection; using System.Xml; +using OpenSim.Framework.Communications.Cache; using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -52,10 +53,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private static readonly ILog m_log = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); + private static string LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI; private bool m_Enabled = false; private bool m_Initialized = false; + private Scene m_aScene; + private Dictionary m_LocalScenes = new Dictionary(); + private IGridService m_GridServiceConnector; private HypergridServiceConnector m_HypergridServiceConnector; @@ -141,6 +146,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (!m_Enabled) return; + m_LocalScenes[scene.RegionInfo.RegionHandle] = scene; scene.RegisterModuleInterface(this); scene.RegisterModuleInterface(this); @@ -148,6 +154,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void RemoveRegion(Scene scene) { + m_LocalScenes.Remove(scene.RegionInfo.RegionHandle); } public void RegionLoaded(Scene scene) @@ -157,7 +164,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (!m_Initialized) { + m_aScene = scene; + LocalAssetServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL; + LocalInventoryServerURI = m_aScene.CommsManager.NetworkServersInfo.InventoryURL; + LocalUserServerURI = m_aScene.CommsManager.NetworkServersInfo.UserURL; + m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); + HGCommands hgCommands = new HGCommands(this, scene); MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-region", "link-region :[:] ", @@ -167,6 +180,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid "Unlink a hypergrid region", hgCommands.RunCommand); MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-mapping", "link-mapping [ ] ", "Set local coordinate to map HG regions to", hgCommands.RunCommand); + + // Yikes!! Remove this as soon as user services get refactored + HGNetworkServersInfo.Init(LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI); + m_Initialized = true; } } @@ -240,7 +257,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid // Try the foreign users home collection foreach (GridRegion r in m_knownRegions.Values) if (r.RegionID == regionID) - return m_knownRegions[regionID]; + return r; // Finally, try the normal route return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); @@ -261,7 +278,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid foreach (GridRegion r in m_knownRegions.Values) { if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) + { return r; + } } // Finally, try the normal route @@ -328,8 +347,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) { - m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); - m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); + m_HyperlinkRegions[regionInfo.RegionID] = regionInfo; + m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; } private void RemoveHyperlinkRegion(UUID regionID) @@ -340,8 +359,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle) { - m_knownRegions.Add(userID, regionInfo); - m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); + m_knownRegions[userID] = regionInfo; + m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; } private void RemoveHyperlinkHomeRegion(UUID regionID) @@ -412,7 +431,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid // From the map search and secondlife://blah public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) { - int xloc = random.Next(0, Int16.MaxValue); + int xloc = random.Next(0, Int16.MaxValue) * (int) Constants.RegionSize; return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); } @@ -563,10 +582,206 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid foreach (GridRegion r in m_HyperlinkRegions.Values) if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) return m_HyperlinkHandles[r.RegionID]; + + foreach (GridRegion r in m_knownRegions.Values) + if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) + return m_HyperlinkHandles[r.RegionID]; + return handle; } + public bool SendUserInformation(GridRegion regInfo, AgentCircuitData agentData) + { + CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID); + + if ((IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) || + (!IsLocalUser(uinfo) && !IsGoingHome(uinfo, regInfo))) + { + m_log.Info("[HGrid]: Local user is going to foreign region or foreign user is going elsewhere"); + + // Set the position of the region on the remote grid + ulong realHandle = FindRegionHandle(regInfo.RegionHandle); + uint x = 0, y = 0; + Utils.LongToUInts(regInfo.RegionHandle, out x, out y); + GridRegion clonedRegion = new GridRegion(regInfo); + clonedRegion.RegionLocX = (int)x; + clonedRegion.RegionLocY = (int)y; + + // Get the user's home region information + GridRegion home = m_aScene.GridService.GetRegionByUUID(m_aScene.RegionInfo.ScopeID, uinfo.UserProfile.HomeRegionID); + + // Get the user's service URLs + string serverURI = ""; + if (uinfo.UserProfile is ForeignUserProfileData) + serverURI = Util.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI); + string userServer = (serverURI == "") || (serverURI == null) ? LocalUserServerURI : serverURI; + + string assetServer = Util.ServerURI(uinfo.UserProfile.UserAssetURI); + if ((assetServer == null) || (assetServer == "")) + assetServer = LocalAssetServerURI; + + string inventoryServer = Util.ServerURI(uinfo.UserProfile.UserInventoryURI); + if ((inventoryServer == null) || (inventoryServer == "")) + inventoryServer = LocalInventoryServerURI; + + if (!m_HypergridServiceConnector.InformRegionOfUser(clonedRegion, agentData, home, userServer, assetServer, inventoryServer)) + { + m_log.Warn("[HGrid]: Could not inform remote region of transferring user."); + return false; + } + } + //if ((uinfo == null) || !IsGoingHome(uinfo, regInfo)) + //{ + // m_log.Info("[HGrid]: User seems to be going to foreign region."); + // if (!InformRegionOfUser(regInfo, agentData)) + // { + // m_log.Warn("[HGrid]: Could not inform remote region of transferring user."); + // return false; + // } + //} + //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) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) + { + agentData.firstname = agentData.firstname + "." + agentData.lastname; + agentData.lastname = "@" + LocalUserServerURI.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI; + } + + return true; + } + + public void AdjustUserInformation(AgentCircuitData agentData) + { + CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID); + if ((uinfo != null) && (uinfo.UserProfile != null) && + (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData))) + { + //m_log.Debug("---------------> Local User!"); + string[] parts = agentData.firstname.Split(new char[] { '.' }); + if (parts.Length == 2) + { + agentData.firstname = parts[0]; + agentData.lastname = parts[1]; + } + } + //else + // m_log.Debug("---------------> Foreign User!"); + } + + // Check if a local user exists with the same UUID as the incoming foreign user + public bool CheckUserAtEntry(UUID userID, UUID sessionID, out bool comingHome) + { + comingHome = false; + if (!m_aScene.SceneGridService.RegionLoginsEnabled) + return false; + + CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID); + if (uinfo != null) + { + // uh-oh we have a potential intruder + if (uinfo.SessionID != sessionID) + // can't have a foreigner with a local UUID + return false; + else + // oh, so it's you! welcome back + comingHome = true; + } + + // OK, user can come in + return true; + } + + public void AcceptUser(ForeignUserProfileData user, GridRegion home) + { + m_aScene.CommsManager.UserProfileCacheService.PreloadUserCache(user); + ulong realHandle = home.RegionHandle; + // Change the local coordinates + // X=0 on the map + home.RegionLocX = 0; + home.RegionLocY = random.Next(0, 10000) * (int)Constants.RegionSize; + + AddHyperlinkHomeRegion(user.ID, home, realHandle); + + DumpUserData(user); + DumpRegionData(home); + + } + + public bool IsLocalUser(UUID userID) + { + CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID); + return IsLocalUser(uinfo); + } + #endregion + #region IHyperlink Misc + + protected bool IsComingHome(ForeignUserProfileData userData) + { + return (userData.UserServerURI == LocalUserServerURI); + } + + // Is the user going back to the home region or the home grid? + protected bool IsGoingHome(CachedUserInfo uinfo, GridRegion rinfo) + { + if (uinfo.UserProfile == null) + return false; + + if (!(uinfo.UserProfile is ForeignUserProfileData)) + // it's a home user, can't be outside to return home + return false; + + // OK, it's a foreign user with a ForeignUserProfileData + // and is going back to exactly the home region. + // We can't check if it's going back to a non-home region + // of the home grid. That will be dealt with in the + // receiving end + return (uinfo.UserProfile.HomeRegionID == rinfo.RegionID); + } + + protected bool IsLocalUser(CachedUserInfo uinfo) + { + if (uinfo == null) + return false; + + return !(uinfo.UserProfile is ForeignUserProfileData); + + } + + protected bool IsLocalRegion(ulong handle) + { + return m_LocalScenes.ContainsKey(handle); + } + + private void DumpUserData(ForeignUserProfileData userData) + { + m_log.Info(" ------------ User Data Dump ----------"); + m_log.Info(" >> Name: " + userData.FirstName + " " + userData.SurName); + m_log.Info(" >> HomeID: " + userData.HomeRegionID); + m_log.Info(" >> UserServer: " + userData.UserServerURI); + m_log.Info(" >> InvServer: " + userData.UserInventoryURI); + m_log.Info(" >> AssetServer: " + userData.UserAssetURI); + m_log.Info(" ------------ -------------- ----------"); + } + + private void DumpRegionData(GridRegion rinfo) + { + m_log.Info(" ------------ Region Data Dump ----------"); + m_log.Info(" >> handle: " + rinfo.RegionHandle); + m_log.Info(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY); + m_log.Info(" >> external host name: " + rinfo.ExternalHostName); + m_log.Info(" >> http port: " + rinfo.HttpPort); + m_log.Info(" >> external EP address: " + rinfo.ExternalEndPoint.Address); + m_log.Info(" >> external EP port: " + rinfo.ExternalEndPoint.Port); + m_log.Info(" ------------ -------------- ----------"); + } + + + #endregion + + } } -- cgit v1.1 From 2432cc607ec206b79149c1e9b1aa995794fec3bc Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 27 Sep 2009 13:43:57 -0700 Subject: Neighbours cache working. --- .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 4 ++ .../Grid/LocalGridServiceConnector.cs | 54 ++++++++++++++++++++-- .../ServiceConnectorsOut/Grid/RegionCache.cs | 52 +++++++++++++++++++++ .../Grid/RemoteGridServiceConnector.cs | 19 ++++++-- 4 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index 52db400..c8062d7 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -135,6 +135,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void PostInitialise() { + ((ISharedRegionModule)m_GridServiceConnector).PostInitialise(); } public void Close() @@ -150,11 +151,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid scene.RegisterModuleInterface(this); scene.RegisterModuleInterface(this); + ((ISharedRegionModule)m_GridServiceConnector).AddRegion(scene); + } public void RemoveRegion(Scene scene) { m_LocalScenes.Remove(scene.RegionInfo.RegionHandle); + ((ISharedRegionModule)m_GridServiceConnector).RemoveRegion(scene); } public void RegionLoaded(Scene scene) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 743d3b9..6c2928a 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using System.Reflection; using OpenSim.Framework; +using OpenSim.Framework.Console; using OpenSim.Server.Base; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -47,7 +48,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); + private static LocalGridServicesConnector m_MainInstance; + private IGridService m_GridService; + private Dictionary m_LocalCache = new Dictionary(); private bool m_Enabled = false; @@ -58,6 +62,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public LocalGridServicesConnector(IConfigSource source) { m_log.Debug("[LOCAL GRID CONNECTOR]: LocalGridServicesConnector instantiated"); + m_MainInstance = this; InitialiseService(source); } @@ -82,6 +87,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (name == Name) { InitialiseService(source); + m_MainInstance = this; m_Enabled = true; m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled"); } @@ -120,6 +126,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void PostInitialise() { + if (m_MainInstance == this) + { + MainConsole.Instance.Commands.AddCommand("LocalGridConnector", false, "show neighbours", + "show neighbours", + "Shows the local regions' neighbours", NeighboursCommand); + } } public void Close() @@ -128,14 +140,26 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void AddRegion(Scene scene) { - if (!m_Enabled) - return; + if (m_Enabled) + scene.RegisterModuleInterface(this); + + if (m_MainInstance == this) + { + if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID)) + m_log.ErrorFormat("[LOCAL GRID CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!"); + else + m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene)); - scene.RegisterModuleInterface(this); + } } public void RemoveRegion(Scene scene) { + if (m_MainInstance == this) + { + m_LocalCache[scene.RegionInfo.RegionID].Clear(); + m_LocalCache.Remove(scene.RegionInfo.RegionID); + } } public void RegionLoaded(Scene scene) @@ -158,7 +182,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public List GetNeighbours(UUID scopeID, UUID regionID) { - return m_GridService.GetNeighbours(scopeID, regionID); + if (m_LocalCache.ContainsKey(regionID)) + { + return m_LocalCache[regionID].GetNeighbours(); + } + else + { + m_log.WarnFormat("[LOCAL GRID CONNECTOR]: GetNeighbours: Requested region {0} is not on this sim", regionID); + return new List(); + } + + // Don't go to the DB + //return m_GridService.GetNeighbours(scopeID, regionID); } public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) @@ -187,5 +222,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid } #endregion + + public void NeighboursCommand(string module, string[] cmdparams) + { + foreach (KeyValuePair kvp in m_LocalCache) + { + m_log.InfoFormat("*** Neighbours of {0} {1} ***", kvp.Key, kvp.Value.RegionName); + List regions = kvp.Value.GetNeighbours(); + foreach (GridRegion r in regions) + m_log.InfoFormat(" {0} @ {1}={2}", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); + } + } } } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs new file mode 100644 index 0000000..ea205a2 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Reflection; + +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; + +using log4net; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid +{ + public class RegionCache + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private Scene m_scene; + private Dictionary m_neighbours = new Dictionary(); + + public string RegionName + { + get { return m_scene.RegionInfo.RegionName; } + } + + public RegionCache(Scene s) + { + m_scene = s; + m_scene.EventManager.OnRegionUp += OnRegionUp; + } + + private void OnRegionUp(GridRegion otherRegion) + { + m_log.DebugFormat("[REGION CACHE]: (on region {0}) Region {1} is up @ {2}-{3}", + m_scene.RegionInfo.RegionName, otherRegion.RegionName, otherRegion.RegionLocX, otherRegion.RegionLocY); + + m_neighbours[otherRegion.RegionHandle] = otherRegion; + } + + public void Clear() + { + m_scene.EventManager.OnRegionUp -= OnRegionUp; + m_neighbours.Clear(); + } + + public List GetNeighbours() + { + return new List(m_neighbours.Values); + } + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs index 91a808b..72c00fc 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs @@ -104,6 +104,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void PostInitialise() { + if (m_LocalGridService != null) + ((ISharedRegionModule)m_LocalGridService).PostInitialise(); } public void Close() @@ -112,14 +114,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void AddRegion(Scene scene) { - if (!m_Enabled) - return; + if (m_Enabled) + scene.RegisterModuleInterface(this); - scene.RegisterModuleInterface(this); + if (m_LocalGridService != null) + ((ISharedRegionModule)m_LocalGridService).AddRegion(scene); } public void RemoveRegion(Scene scene) { + if (m_LocalGridService != null) + ((ISharedRegionModule)m_LocalGridService).RemoveRegion(scene); } public void RegionLoaded(Scene scene) @@ -146,7 +151,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid return false; } - // Let's not override GetNeighbours -- let's get them all from the grid server + // Let's override GetNeighbours completely -- never go to the grid server + // Neighbours are/should be cached locally + // For retrieval from the DB, caller should call GetRegionByPosition + public override List GetNeighbours(UUID scopeID, UUID regionID) + { + return m_LocalGridService.GetNeighbours(scopeID, regionID); + } public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) { -- cgit v1.1 From 689eea3bad7a7dd7fa8dfdacacd891e1d390e51e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 27 Sep 2009 15:06:44 -0700 Subject: Guarding the methods under if (m_Enabled) --- .../CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index c8062d7..1eb481e 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -135,7 +135,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void PostInitialise() { - ((ISharedRegionModule)m_GridServiceConnector).PostInitialise(); + if (m_Enabled) + ((ISharedRegionModule)m_GridServiceConnector).PostInitialise(); } public void Close() @@ -157,8 +158,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public void RemoveRegion(Scene scene) { - m_LocalScenes.Remove(scene.RegionInfo.RegionHandle); - ((ISharedRegionModule)m_GridServiceConnector).RemoveRegion(scene); + if (m_Enabled) + { + m_LocalScenes.Remove(scene.RegionInfo.RegionHandle); + ((ISharedRegionModule)m_GridServiceConnector).RemoveRegion(scene); + } } public void RegionLoaded(Scene scene) -- cgit v1.1 From f00126dc2dfc9e23aa50227f02ee9adbe1efdfa6 Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Tue, 29 Sep 2009 08:32:59 +0900 Subject: Add copyright header. Formatting cleanup. --- .../ServiceConnectorsOut/Grid/RegionCache.cs | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs index ea205a2..2b336bb 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs @@ -1,4 +1,31 @@ -using System; +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; using System.Collections.Generic; using System.Reflection; -- cgit v1.1 From 4eca59ec13bb48309120fea24890341c65157c65 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 28 Sep 2009 17:33:34 -0700 Subject: Improved the Local grid connector to fetch data from the DB when it doesn't find it in the cache. Commented out the Standalone teleport test because it's failing, and the scene setup is very confusing. I suspect it may be wrong -- the connectors-as-ISharedRegionModules are being instantiated several times when there are several scenes. --- .../ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | 7 +++++-- .../ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 6c2928a..3ca4882 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs @@ -149,7 +149,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid m_log.ErrorFormat("[LOCAL GRID CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!"); else m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene)); - } } @@ -184,7 +183,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { if (m_LocalCache.ContainsKey(regionID)) { - return m_LocalCache[regionID].GetNeighbours(); + List neighbours = m_LocalCache[regionID].GetNeighbours(); + if (neighbours.Count == 0) + // try the DB + neighbours = m_GridService.GetNeighbours(scopeID, regionID); + return neighbours; } else { diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs index be32d6b..2ca90f8 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs @@ -78,6 +78,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests r1.ExternalHostName = "127.0.0.1"; r1.HttpPort = 9001; r1.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); + Scene s = new Scene(new RegionInfo()); + s.RegionInfo.RegionID = r1.RegionID; + m_LocalConnector.AddRegion(s); + GridRegion r2 = new GridRegion(); r2.RegionName = "Test Region 2"; @@ -87,6 +91,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests r2.ExternalHostName = "127.0.0.1"; r2.HttpPort = 9002; r2.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); + s = new Scene(new RegionInfo()); + s.RegionInfo.RegionID = r1.RegionID; + m_LocalConnector.AddRegion(s); GridRegion r3 = new GridRegion(); r3.RegionName = "Test Region 3"; @@ -96,6 +103,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests r3.ExternalHostName = "127.0.0.1"; r3.HttpPort = 9003; r3.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); + s = new Scene(new RegionInfo()); + s.RegionInfo.RegionID = r1.RegionID; + m_LocalConnector.AddRegion(s); m_LocalConnector.RegisterRegion(UUID.Zero, r1); GridRegion result = m_LocalConnector.GetRegionByName(UUID.Zero, "Test"); -- cgit v1.1 From 95981776dda88f97c4a1d016e1e266e8ff1d54aa Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 28 Sep 2009 20:11:10 -0700 Subject: Fixed bug in Check4096 (HG). --- .../Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index 1eb481e..148331b 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -554,8 +554,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid x = (int)(ux / Constants.RegionSize); y = (int)(uy / Constants.RegionSize); - if ((Math.Abs((int)(m_scene.RegionInfo.RegionLocX / Constants.RegionSize) - x) >= 4096) || - (Math.Abs((int)(m_scene.RegionInfo.RegionLocY / Constants.RegionSize) - y) >= 4096)) + if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - x) >= 4096) || + (Math.Abs((int)m_scene.RegionInfo.RegionLocY - y) >= 4096)) { return false; } -- cgit v1.1