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. --- OpenSim/Data/Null/NullRegionData.cs | 1 + .../ServiceConnectorsOut/Grid/HGCommands.cs | 36 +-- .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 82 +++---- .../Grid/LocalGridServiceConnector.cs | 18 +- .../Grid/RemoteGridServiceConnector.cs | 15 +- .../Server/Handlers/Grid/GridServerPostHandler.cs | 7 +- .../Connectors/Grid/GridServiceConnector.cs | 39 ++-- .../Connectors/Grid/HypergridServiceConnector.cs | 5 +- OpenSim/Services/GridService/GridService.cs | 32 +-- OpenSim/Services/GridService/GridServiceBase.cs | 2 +- OpenSim/Services/Interfaces/IGridService.cs | 249 ++++++++++++++++++++- 11 files changed, 368 insertions(+), 118 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/Null/NullRegionData.cs b/OpenSim/Data/Null/NullRegionData.cs index 588b8ac..03489f9 100644 --- a/OpenSim/Data/Null/NullRegionData.cs +++ b/OpenSim/Data/Null/NullRegionData.cs @@ -40,6 +40,7 @@ namespace OpenSim.Data.Null public NullRegionData(string connectionString, string realm) { + Console.WriteLine("[XXX] NullRegionData constructor"); } public List Get(string regionName, UUID scopeID) 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); diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs index 39c0584..e72c2eb 100644 --- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs @@ -38,6 +38,7 @@ using System.Xml.Serialization; using System.Collections.Generic; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; using OpenSim.Framework; using OpenSim.Framework.Servers.HttpServer; using OpenMetaverse; @@ -117,7 +118,7 @@ namespace OpenSim.Server.Handlers.Grid Dictionary rinfoData = new Dictionary(); foreach (KeyValuePair kvp in request) rinfoData[kvp.Key] = kvp.Value; - SimpleRegionInfo rinfo = new SimpleRegionInfo(rinfoData); + GridRegion rinfo = new GridRegion(rinfoData); bool result = m_GridService.RegisterRegion(scopeID, rinfo); @@ -158,11 +159,11 @@ namespace OpenSim.Server.Handlers.Grid else m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours"); - List rinfos = m_GridService.GetNeighbours(scopeID, regionID); + List rinfos = m_GridService.GetNeighbours(scopeID, regionID); Dictionary result = new Dictionary(); int i = 0; - foreach (SimpleRegionInfo rinfo in rinfos) + foreach (GridRegion rinfo in rinfos) { Dictionary rinfoDict = rinfo.ToKeyValuePairs(); result["region" + i] = rinfoDict; diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs index 1962bcf..0a867db 100644 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs @@ -35,6 +35,7 @@ using OpenSim.Framework; using OpenSim.Framework.Communications; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; using OpenSim.Server.Base; using OpenMetaverse; @@ -85,7 +86,7 @@ namespace OpenSim.Services.Connectors #region IGridService - public virtual bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) + public virtual bool RegisterRegion(UUID scopeID, GridRegion regionInfo) { Dictionary rinfo = regionInfo.ToKeyValuePairs(); Dictionary sendData = new Dictionary(); @@ -128,7 +129,7 @@ namespace OpenSim.Services.Connectors return false; } - public virtual List GetNeighbours(UUID scopeID, UUID regionID) + public virtual List GetNeighbours(UUID scopeID, UUID regionID) { Dictionary sendData = new Dictionary(); @@ -143,7 +144,7 @@ namespace OpenSim.Services.Connectors Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - List rinfos = new List(); + List rinfos = new List(); if (replyData != null) { Dictionary.ValueCollection rinfosList = replyData.Values; @@ -151,7 +152,7 @@ namespace OpenSim.Services.Connectors { if (r is Dictionary) { - SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary)r); + GridRegion rinfo = new GridRegion((Dictionary)r); rinfos.Add(rinfo); } else @@ -166,7 +167,7 @@ namespace OpenSim.Services.Connectors return rinfos; } - public virtual SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) + public virtual GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) { Dictionary sendData = new Dictionary(); @@ -181,11 +182,11 @@ namespace OpenSim.Services.Connectors Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - SimpleRegionInfo rinfo = null; + GridRegion rinfo = null; if ((replyData != null) && (replyData["result"] != null)) { if (replyData["result"] is Dictionary) - rinfo = new SimpleRegionInfo((Dictionary)replyData["result"]); + rinfo = new GridRegion((Dictionary)replyData["result"]); else m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received invalid response", scopeID, regionID); @@ -197,7 +198,7 @@ namespace OpenSim.Services.Connectors return rinfo; } - public virtual SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) + public virtual GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { Dictionary sendData = new Dictionary(); @@ -213,11 +214,11 @@ namespace OpenSim.Services.Connectors Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - SimpleRegionInfo rinfo = null; + GridRegion rinfo = null; if ((replyData != null) && (replyData["result"] != null)) { if (replyData["result"] is Dictionary) - rinfo = new SimpleRegionInfo((Dictionary)replyData["result"]); + rinfo = new GridRegion((Dictionary)replyData["result"]); else m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received invalid response", scopeID, x, y); @@ -229,7 +230,7 @@ namespace OpenSim.Services.Connectors return rinfo; } - public virtual SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) + public virtual GridRegion GetRegionByName(UUID scopeID, string regionName) { Dictionary sendData = new Dictionary(); @@ -244,11 +245,11 @@ namespace OpenSim.Services.Connectors Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - SimpleRegionInfo rinfo = null; + GridRegion rinfo = null; if ((replyData != null) && (replyData["result"] != null)) { if (replyData["result"] is Dictionary) - rinfo = new SimpleRegionInfo((Dictionary)replyData["result"]); + rinfo = new GridRegion((Dictionary)replyData["result"]); else m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received invalid response", scopeID, regionName); @@ -260,7 +261,7 @@ namespace OpenSim.Services.Connectors return rinfo; } - public virtual List GetRegionsByName(UUID scopeID, string name, int maxNumber) + public virtual List GetRegionsByName(UUID scopeID, string name, int maxNumber) { Dictionary sendData = new Dictionary(); @@ -276,7 +277,7 @@ namespace OpenSim.Services.Connectors Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - List rinfos = new List(); + List rinfos = new List(); if (replyData != null) { Dictionary.ValueCollection rinfosList = replyData.Values; @@ -284,7 +285,7 @@ namespace OpenSim.Services.Connectors { if (r is Dictionary) { - SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary)r); + GridRegion rinfo = new GridRegion((Dictionary)r); rinfos.Add(rinfo); } else @@ -299,7 +300,7 @@ namespace OpenSim.Services.Connectors return rinfos; } - public virtual List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) + public virtual List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) { Dictionary sendData = new Dictionary(); @@ -317,7 +318,7 @@ namespace OpenSim.Services.Connectors Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - List rinfos = new List(); + List rinfos = new List(); if (replyData != null) { Dictionary.ValueCollection rinfosList = replyData.Values; @@ -325,7 +326,7 @@ namespace OpenSim.Services.Connectors { if (r is Dictionary) { - SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary)r); + GridRegion rinfo = new GridRegion((Dictionary)r); rinfos.Add(rinfo); } else diff --git a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs index 6b0518c..616c2c1 100644 --- a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs @@ -33,6 +33,7 @@ using System.Drawing; using System.Net; using System.Reflection; using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; using OpenSim.Framework; @@ -54,7 +55,7 @@ namespace OpenSim.Services.Connectors.Grid m_AssetService = assService; } - public UUID LinkRegion(SimpleRegionInfo info, out ulong realHandle) + public UUID LinkRegion(GridRegion info, out ulong realHandle) { UUID uuid = UUID.Zero; realHandle = 0; @@ -114,7 +115,7 @@ namespace OpenSim.Services.Connectors.Grid return uuid; } - public void GetMapImage(SimpleRegionInfo info) + public void GetMapImage(GridRegion info) { try { diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs index b37a51b..cd462ab 100644 --- a/OpenSim/Services/GridService/GridService.cs +++ b/OpenSim/Services/GridService/GridService.cs @@ -35,6 +35,7 @@ using OpenSim.Framework; using OpenSim.Framework.Console; using OpenSim.Data; using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; using OpenMetaverse; namespace OpenSim.Services.GridService @@ -48,6 +49,7 @@ namespace OpenSim.Services.GridService public GridService(IConfigSource config) : base(config) { + m_log.DebugFormat("[GRID SERVICE]: Starting..."); MainConsole.Instance.Commands.AddCommand("kfs", false, "show digest", "show digest ", @@ -62,7 +64,7 @@ namespace OpenSim.Services.GridService #region IGridService - public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfos) + public bool RegisterRegion(UUID scopeID, GridRegion regionInfos) { if (m_Database.Get(regionInfos.RegionID, scopeID) != null) { @@ -88,9 +90,9 @@ namespace OpenSim.Services.GridService return m_Database.Delete(regionID); } - public List GetNeighbours(UUID scopeID, UUID regionID) + public List GetNeighbours(UUID scopeID, UUID regionID) { - List rinfos = new List(); + List rinfos = new List(); RegionData region = m_Database.Get(regionID, scopeID); if (region != null) { @@ -105,7 +107,7 @@ namespace OpenSim.Services.GridService return rinfos; } - public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) + public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) { RegionData rdata = m_Database.Get(regionID, scopeID); if (rdata != null) @@ -114,7 +116,7 @@ namespace OpenSim.Services.GridService return null; } - 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; @@ -125,7 +127,7 @@ namespace OpenSim.Services.GridService return null; } - public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) + public GridRegion GetRegionByName(UUID scopeID, string regionName) { List rdatas = m_Database.Get(regionName + "%", scopeID); if ((rdatas != null) && (rdatas.Count > 0)) @@ -134,12 +136,12 @@ namespace OpenSim.Services.GridService return null; } - public List GetRegionsByName(UUID scopeID, string name, int maxNumber) + public List GetRegionsByName(UUID scopeID, string name, int maxNumber) { List rdatas = m_Database.Get("%" + name + "%", scopeID); int count = 0; - List rinfos = new List(); + List rinfos = new List(); if (rdatas != null) { @@ -153,7 +155,7 @@ namespace OpenSim.Services.GridService 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 xminSnap = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize; int xmaxSnap = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize; @@ -161,7 +163,7 @@ namespace OpenSim.Services.GridService int ymaxSnap = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize; List rdatas = m_Database.Get(xminSnap, yminSnap, xmaxSnap, ymaxSnap, scopeID); - List rinfos = new List(); + List rinfos = new List(); foreach (RegionData rdata in rdatas) rinfos.Add(RegionData2RegionInfo(rdata)); @@ -172,7 +174,7 @@ namespace OpenSim.Services.GridService #region Data structure conversions - protected RegionData RegionInfo2RegionData(SimpleRegionInfo rinfo) + protected RegionData RegionInfo2RegionData(GridRegion rinfo) { RegionData rdata = new RegionData(); rdata.posX = (int)rinfo.RegionLocX; @@ -184,11 +186,11 @@ namespace OpenSim.Services.GridService return rdata; } - protected SimpleRegionInfo RegionData2RegionInfo(RegionData rdata) + protected GridRegion RegionData2RegionInfo(RegionData rdata) { - SimpleRegionInfo rinfo = new SimpleRegionInfo(rdata.Data); - rinfo.RegionLocX = (uint)rdata.posX; - rinfo.RegionLocY = (uint)rdata.posY; + GridRegion rinfo = new GridRegion(rdata.Data); + rinfo.RegionLocX = rdata.posX; + rinfo.RegionLocY = rdata.posY; rinfo.RegionID = rdata.RegionID; rinfo.RegionName = rdata.RegionName; diff --git a/OpenSim/Services/GridService/GridServiceBase.cs b/OpenSim/Services/GridService/GridServiceBase.cs index 7522e64..444f79b 100644 --- a/OpenSim/Services/GridService/GridServiceBase.cs +++ b/OpenSim/Services/GridService/GridServiceBase.cs @@ -68,7 +68,7 @@ namespace OpenSim.Services.GridService connString = gridConfig.GetString("ConnectionString", connString); realm = gridConfig.GetString("Realm", realm); } - + // // We tried, but this doesn't exist. We can't proceed. // diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs index 8f6c524..a188f7e 100644 --- a/OpenSim/Services/Interfaces/IGridService.cs +++ b/OpenSim/Services/Interfaces/IGridService.cs @@ -25,8 +25,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -using OpenSim.Framework; +using System; using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using OpenSim.Framework; using OpenMetaverse; namespace OpenSim.Services.Interfaces @@ -39,7 +42,7 @@ namespace OpenSim.Services.Interfaces /// /// /// Thrown if region registration failed - bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfos); + bool RegisterRegion(UUID scopeID, GridRegion regionInfos); /// /// Deregister a region with the grid service. @@ -55,9 +58,9 @@ namespace OpenSim.Services.Interfaces /// /// /// - List GetNeighbours(UUID scopeID, UUID regionID); + List GetNeighbours(UUID scopeID, UUID regionID); - SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID); + GridRegion GetRegionByUUID(UUID scopeID, UUID regionID); /// /// Get the region at the given position (in meters) @@ -66,9 +69,9 @@ namespace OpenSim.Services.Interfaces /// /// /// - SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y); - - SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName); + GridRegion GetRegionByPosition(UUID scopeID, int x, int y); + + GridRegion GetRegionByName(UUID scopeID, string regionName); /// /// Get information about regions starting with the provided name. @@ -83,9 +86,237 @@ namespace OpenSim.Services.Interfaces /// A list of s of regions with matching name. If the /// grid-server couldn't be contacted or returned an error, return null. /// - List GetRegionsByName(UUID scopeID, string name, int maxNumber); + List GetRegionsByName(UUID scopeID, string name, int maxNumber); - List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax); + List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax); } + + public class GridRegion + { + + /// + /// The port by which http communication occurs with the region + /// + public uint HttpPort + { + get { return m_httpPort; } + set { m_httpPort = value; } + } + protected uint m_httpPort; + + /// + /// A well-formed URI for the host region server (namely "http://" + ExternalHostName) + /// + public string ServerURI + { + get { return m_serverURI; } + set { m_serverURI = value; } + } + protected string m_serverURI; + + public string RegionName + { + get { return m_regionName; } + set { m_regionName = value; } + } + protected string m_regionName = String.Empty; + + protected bool Allow_Alternate_Ports; + public bool m_allow_alternate_ports; + + protected string m_externalHostName; + + protected IPEndPoint m_internalEndPoint; + + public int RegionLocX + { + get { return m_regionLocX; } + set { m_regionLocX = value; } + } + protected int m_regionLocX; + + public int RegionLocY + { + get { return m_regionLocY; } + set { m_regionLocY = value; } + } + protected int m_regionLocY; + + public UUID RegionID = UUID.Zero; + public UUID ScopeID = UUID.Zero; + + public GridRegion() + { + } + + public GridRegion(int regionLocX, int regionLocY, IPEndPoint internalEndPoint, string externalUri) + { + m_regionLocX = regionLocX; + m_regionLocY = regionLocY; + + m_internalEndPoint = internalEndPoint; + m_externalHostName = externalUri; + } + + public GridRegion(int regionLocX, int regionLocY, string externalUri, uint port) + { + m_regionLocX = regionLocX; + m_regionLocY = regionLocY; + + m_externalHostName = externalUri; + + m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)port); + } + + public GridRegion(uint xcell, uint ycell) + { + m_regionLocX = (int)(xcell * Constants.RegionSize); + m_regionLocY = (int)(ycell * Constants.RegionSize); + } + + public GridRegion(RegionInfo ConvertFrom) + { + m_regionName = ConvertFrom.RegionName; + m_regionLocX = (int)(ConvertFrom.RegionLocX * Constants.RegionSize); + m_regionLocY = (int)(ConvertFrom.RegionLocY * Constants.RegionSize); + m_internalEndPoint = ConvertFrom.InternalEndPoint; + m_externalHostName = ConvertFrom.ExternalHostName; + m_httpPort = ConvertFrom.HttpPort; + m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports; + RegionID = UUID.Zero; + ServerURI = ConvertFrom.ServerURI; + } + + + /// + /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw. + /// + /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method? + /// + public IPEndPoint ExternalEndPoint + { + get + { + // Old one defaults to IPv6 + //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port); + + IPAddress ia = null; + // If it is already an IP, don't resolve it - just return directly + if (IPAddress.TryParse(m_externalHostName, out ia)) + return new IPEndPoint(ia, m_internalEndPoint.Port); + + // Reset for next check + ia = null; + try + { + foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName)) + { + if (ia == null) + ia = Adr; + + if (Adr.AddressFamily == AddressFamily.InterNetwork) + { + ia = Adr; + break; + } + } + } + catch (SocketException e) + { + throw new Exception( + "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" + + e + "' attached to this exception", e); + } + + return new IPEndPoint(ia, m_internalEndPoint.Port); + } + + set { m_externalHostName = value.ToString(); } + } + + public string ExternalHostName + { + get { return m_externalHostName; } + set { m_externalHostName = value; } + } + + public IPEndPoint InternalEndPoint + { + get { return m_internalEndPoint; } + set { m_internalEndPoint = value; } + } + + public ulong RegionHandle + { + get { return Util.UIntsToLong((uint)RegionLocX, (uint)RegionLocY); } + } + + public int getInternalEndPointPort() + { + return m_internalEndPoint.Port; + } + + public Dictionary ToKeyValuePairs() + { + Dictionary kvp = new Dictionary(); + kvp["uuid"] = RegionID.ToString(); + kvp["locX"] = RegionLocX.ToString(); + kvp["locY"] = RegionLocY.ToString(); + kvp["external_ip_address"] = ExternalEndPoint.Address.ToString(); + kvp["external_port"] = ExternalEndPoint.Port.ToString(); + kvp["external_host_name"] = ExternalHostName; + kvp["http_port"] = HttpPort.ToString(); + kvp["internal_ip_address"] = InternalEndPoint.Address.ToString(); + kvp["internal_port"] = InternalEndPoint.Port.ToString(); + kvp["alternate_ports"] = m_allow_alternate_ports.ToString(); + kvp["server_uri"] = ServerURI; + + return kvp; + } + + public GridRegion(Dictionary kvp) + { + if ((kvp["external_ip_address"] != null) && (kvp["external_port"] != null)) + { + int port = 0; + Int32.TryParse((string)kvp["external_port"], out port); + IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["external_ip_address"]), port); + ExternalEndPoint = ep; + } + else + ExternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); + + if (kvp["external_host_name"] != null) + ExternalHostName = (string)kvp["external_host_name"]; + + if (kvp["http_port"] != null) + { + UInt32 port = 0; + UInt32.TryParse((string)kvp["http_port"], out port); + HttpPort = port; + } + + if ((kvp["internal_ip_address"] != null) && (kvp["internal_port"] != null)) + { + int port = 0; + Int32.TryParse((string)kvp["internal_port"], out port); + IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["internal_ip_address"]), port); + InternalEndPoint = ep; + } + else + InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); + + if (kvp["alternate_ports"] != null) + { + bool alts = false; + Boolean.TryParse((string)kvp["alternate_ports"], out alts); + m_allow_alternate_ports = alts; + } + + if (kvp["server_uri"] != null) + ServerURI = (string)kvp["server_uri"]; + } + } + } -- cgit v1.1