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