aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/RegionInfo.cs62
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs4
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerConnector.cs60
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs269
-rw-r--r--OpenSim/Services/Connectors/Grid/GridServiceConnector.cs346
-rw-r--r--OpenSim/Services/GridService/GridService.cs65
-rw-r--r--OpenSim/Services/Interfaces/IGridService.cs2
7 files changed, 751 insertions, 57 deletions
diff --git a/OpenSim/Framework/RegionInfo.cs b/OpenSim/Framework/RegionInfo.cs
index 3896a6e..afd50a9 100644
--- a/OpenSim/Framework/RegionInfo.cs
+++ b/OpenSim/Framework/RegionInfo.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.Net; 30using System.Net;
30using System.Net.Sockets; 31using System.Net.Sockets;
31using System.Xml; 32using System.Xml;
@@ -197,6 +198,67 @@ namespace OpenSim.Framework
197 { 198 {
198 return m_internalEndPoint.Port; 199 return m_internalEndPoint.Port;
199 } 200 }
201
202 public Dictionary<string, object> ToKeyValuePairs()
203 {
204 Dictionary<string, object> kvp = new Dictionary<string, object>();
205 kvp["uuid"] = RegionID.ToString();
206 kvp["locX"] = RegionLocX.ToString();
207 kvp["locY"] = RegionLocY.ToString();
208 kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
209 kvp["external_port"] = ExternalEndPoint.Port.ToString();
210 kvp["external_host_name"] = ExternalHostName;
211 kvp["http_port"] = HttpPort.ToString();
212 kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
213 kvp["internal_port"] = InternalEndPoint.Port.ToString();
214 kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
215 kvp["server_uri"] = ServerURI;
216
217 return kvp;
218 }
219
220 public SimpleRegionInfo(Dictionary<string, object> kvp)
221 {
222 if ((kvp["external_ip_address"] != null) && (kvp["external_port"] != null))
223 {
224 int port = 0;
225 Int32.TryParse((string)kvp["external_port"], out port);
226 IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["external_ip_address"]), port);
227 ExternalEndPoint = ep;
228 }
229 else
230 ExternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
231
232 if (kvp["external_host_name"] != null)
233 ExternalHostName = (string)kvp["external_host_name"];
234
235 if (kvp["http_port"] != null)
236 {
237 UInt32 port = 0;
238 UInt32.TryParse((string)kvp["http_port"], out port);
239 HttpPort = port;
240 }
241
242 if ((kvp["internal_ip_address"] != null) && (kvp["internal_port"] != null))
243 {
244 int port = 0;
245 Int32.TryParse((string)kvp["internal_port"], out port);
246 IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["internal_ip_address"]), port);
247 InternalEndPoint = ep;
248 }
249 else
250 InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
251
252 if (kvp["alternate_ports"] != null)
253 {
254 bool alts = false;
255 Boolean.TryParse((string)kvp["alternate_ports"], out alts);
256 m_allow_alternate_ports = alts;
257 }
258
259 if (kvp["server_uri"] != null)
260 ServerURI = (string)kvp["server_uri"];
261 }
200 } 262 }
201 263
202 public class RegionInfo : SimpleRegionInfo 264 public class RegionInfo : SimpleRegionInfo
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
index 6475817..74ece2e 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
@@ -140,9 +140,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
140 return m_GridService.DeregisterRegion(regionID); 140 return m_GridService.DeregisterRegion(regionID);
141 } 141 }
142 142
143 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, int x, int y) 143 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID)
144 { 144 {
145 return m_GridService.GetNeighbours(scopeID, x, y); 145 return m_GridService.GetNeighbours(scopeID, regionID);
146 } 146 }
147 147
148 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) 148 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID)
diff --git a/OpenSim/Server/Handlers/Grid/GridServerConnector.cs b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
new file mode 100644
index 0000000..b80c479
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
@@ -0,0 +1,60 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34
35namespace OpenSim.Server.Handlers.Grid
36{
37 public class GridServiceConnector : ServiceConnector
38 {
39 private IGridService m_GridService;
40
41 public GridServiceConnector(IConfigSource config, IHttpServer server) :
42 base(config, server)
43 {
44 IConfig serverConfig = config.Configs["GridService"];
45 if (serverConfig == null)
46 throw new Exception("No section 'Server' in config file");
47
48 string gridService = serverConfig.GetString("GridServiceModule",
49 String.Empty);
50
51 if (gridService == String.Empty)
52 throw new Exception("No AuthenticationService in config file");
53
54 Object[] args = new Object[] { config };
55 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
56
57 server.AddStreamHandler(new GridServerPostHandler(m_GridService));
58 }
59 }
60}
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
new file mode 100644
index 0000000..39c0584
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
@@ -0,0 +1,269 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework;
42using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.Grid
46{
47 public class GridServerPostHandler : BaseStreamHandler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IGridService m_GridService;
52
53 public GridServerPostHandler(IGridService service) :
54 base("POST", "/grid")
55 {
56 m_GridService = service;
57 }
58
59 public override byte[] Handle(string path, Stream requestData,
60 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
61 {
62 StreamReader sr = new StreamReader(requestData);
63 string body = sr.ReadToEnd();
64 sr.Close();
65
66 Dictionary<string, string> request =
67 ServerUtils.ParseQueryString(body);
68
69 if (!request.ContainsKey("METHOD"))
70 return FailureResult();
71
72 string method = request["METHOD"];
73
74 switch (method)
75 {
76 case "register":
77 return Register(request);
78
79 case "deregister":
80 return Deregister(request);
81
82 case "get_neighbours":
83 return GetNeighbours(request);
84
85 case "get_region_by_uuid":
86 return GetRegionByUUID(request);
87
88 case "get_region_by_position":
89 return GetRegionByPosition(request);
90
91 case "get_region_by_name":
92 return GetRegionByName(request);
93
94 case "get_regions_by_name":
95 return GetRegionsByName(request);
96
97 case "get_region_range":
98 return GetRegionRange(request);
99
100 default:
101 m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method);
102 return FailureResult();
103 }
104
105 }
106
107 #region Method-specific handlers
108
109 byte[] Register(Dictionary<string, string> request)
110 {
111 UUID scopeID = UUID.Zero;
112 if (request["SCOPEID"] != null)
113 UUID.TryParse(request["SCOPEID"], out scopeID);
114 else
115 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
116
117 Dictionary<string, object> rinfoData = new Dictionary<string, object>();
118 foreach (KeyValuePair<string, string> kvp in request)
119 rinfoData[kvp.Key] = kvp.Value;
120 SimpleRegionInfo rinfo = new SimpleRegionInfo(rinfoData);
121
122 bool result = m_GridService.RegisterRegion(scopeID, rinfo);
123
124 if (result)
125 return SuccessResult();
126 else
127 return FailureResult();
128 }
129
130 byte[] Deregister(Dictionary<string, string> request)
131 {
132 UUID regionID = UUID.Zero;
133 if (request["REGIONID"] != null)
134 UUID.TryParse(request["REGIONID"], out regionID);
135 else
136 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
137
138 bool result = m_GridService.DeregisterRegion(regionID);
139
140 if (result)
141 return SuccessResult();
142 else
143 return FailureResult();
144
145 }
146
147 byte[] GetNeighbours(Dictionary<string, string> request)
148 {
149 UUID scopeID = UUID.Zero;
150 if (request["SCOPEID"] != null)
151 UUID.TryParse(request["SCOPEID"], out scopeID);
152 else
153 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
154
155 UUID regionID = UUID.Zero;
156 if (request["REGIONID"] != null)
157 UUID.TryParse(request["REGIONID"], out scopeID);
158 else
159 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
160
161 List<SimpleRegionInfo> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
162
163 Dictionary<string, object> result = new Dictionary<string, object>();
164 int i = 0;
165 foreach (SimpleRegionInfo rinfo in rinfos)
166 {
167 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
168 result["region" + i] = rinfoDict;
169 i++;
170 }
171
172 string xmlString = ServerUtils.BuildXmlResponse(result);
173 UTF8Encoding encoding = new UTF8Encoding();
174 return encoding.GetBytes(xmlString);
175
176 }
177
178 byte[] GetRegionByUUID(Dictionary<string, string> request)
179 {
180 // TODO
181 return new byte[0];
182 }
183
184 byte[] GetRegionByPosition(Dictionary<string, string> request)
185 {
186 // TODO
187 return new byte[0];
188 }
189
190 byte[] GetRegionByName(Dictionary<string, string> request)
191 {
192 // TODO
193 return new byte[0];
194 }
195
196 byte[] GetRegionsByName(Dictionary<string, string> request)
197 {
198 // TODO
199 return new byte[0];
200 }
201
202 byte[] GetRegionRange(Dictionary<string, string> request)
203 {
204 // TODO
205 return new byte[0];
206 }
207
208 #endregion
209
210 #region Misc
211
212 private byte[] SuccessResult()
213 {
214 XmlDocument doc = new XmlDocument();
215
216 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
217 "", "");
218
219 doc.AppendChild(xmlnode);
220
221 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
222 "");
223
224 doc.AppendChild(rootElement);
225
226 XmlElement result = doc.CreateElement("", "Result", "");
227 result.AppendChild(doc.CreateTextNode("Success"));
228
229 rootElement.AppendChild(result);
230
231 return DocToBytes(doc);
232 }
233
234 private byte[] FailureResult()
235 {
236 XmlDocument doc = new XmlDocument();
237
238 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
239 "", "");
240
241 doc.AppendChild(xmlnode);
242
243 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
244 "");
245
246 doc.AppendChild(rootElement);
247
248 XmlElement result = doc.CreateElement("", "Result", "");
249 result.AppendChild(doc.CreateTextNode("Failure"));
250
251 rootElement.AppendChild(result);
252
253 return DocToBytes(doc);
254 }
255
256 private byte[] DocToBytes(XmlDocument doc)
257 {
258 MemoryStream ms = new MemoryStream();
259 XmlTextWriter xw = new XmlTextWriter(ms, null);
260 xw.Formatting = Formatting.Indented;
261 doc.WriteTo(xw);
262 xw.Flush();
263
264 return ms.GetBuffer();
265 }
266
267 #endregion
268 }
269}
diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs
new file mode 100644
index 0000000..ae7db7e
--- /dev/null
+++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs
@@ -0,0 +1,346 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces;
38using OpenSim.Server.Base;
39using OpenMetaverse;
40
41namespace OpenSim.Services.Connectors
42{
43 public class GridServicesConnector : IGridService
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(
47 MethodBase.GetCurrentMethod().DeclaringType);
48
49 private string m_ServerURI = String.Empty;
50
51 public GridServicesConnector()
52 {
53 }
54
55 public GridServicesConnector(string serverURI)
56 {
57 m_ServerURI = serverURI.TrimEnd('/');
58 }
59
60 public GridServicesConnector(IConfigSource source)
61 {
62 Initialise(source);
63 }
64
65 public virtual void Initialise(IConfigSource source)
66 {
67 IConfig gridConfig = source.Configs["GridService"];
68 if (gridConfig == null)
69 {
70 m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini");
71 throw new Exception("Grid connector init error");
72 }
73
74 string serviceURI = gridConfig.GetString("GridServerURI",
75 String.Empty);
76
77 if (serviceURI == String.Empty)
78 {
79 m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService");
80 throw new Exception("Grid connector init error");
81 }
82 m_ServerURI = serviceURI;
83 }
84
85
86 #region IGridService
87
88 public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo)
89 {
90 Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs();
91 Dictionary<string, string> sendData = new Dictionary<string,string>();
92 foreach (KeyValuePair<string, object> kvp in rinfo)
93 sendData[kvp.Key] = (string)kvp.Value;
94
95 sendData["SCOPEID"] = scopeID.ToString();
96
97 sendData["METHOD"] = "register";
98
99 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
100 m_ServerURI + "/grid",
101 ServerUtils.BuildQueryString(sendData));
102
103 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
104
105 if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success"))
106 return true;
107
108 return false;
109 }
110
111 public bool DeregisterRegion(UUID regionID)
112 {
113 Dictionary<string, string> sendData = new Dictionary<string, string>();
114
115 sendData["REGIONID"] = regionID.ToString();
116
117 sendData["METHOD"] = "deregister";
118
119 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
120 m_ServerURI + "/grid",
121 ServerUtils.BuildQueryString(sendData));
122
123 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
124
125 if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success"))
126 return true;
127
128 return false;
129 }
130
131 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID)
132 {
133 Dictionary<string, string> sendData = new Dictionary<string, string>();
134
135 sendData["SCOPEID"] = scopeID.ToString();
136 sendData["REGIONID"] = regionID.ToString();
137
138 sendData["METHOD"] = "get_neighbours";
139
140 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
141 m_ServerURI + "/grid",
142 ServerUtils.BuildQueryString(sendData));
143
144 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
145
146 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
147 if (replyData != null)
148 {
149 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
150 foreach (object r in rinfosList)
151 {
152 if (r is Dictionary<string, object>)
153 {
154 SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r);
155 rinfos.Add(rinfo);
156 }
157 else
158 m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received invalid response",
159 scopeID, regionID);
160 }
161 }
162 else
163 m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received null response",
164 scopeID, regionID);
165
166 return rinfos;
167 }
168
169 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID)
170 {
171 Dictionary<string, string> sendData = new Dictionary<string, string>();
172
173 sendData["SCOPEID"] = scopeID.ToString();
174 sendData["REGIONID"] = regionID.ToString();
175
176 sendData["METHOD"] = "get_region_by_uuid";
177
178 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
179 m_ServerURI + "/grid",
180 ServerUtils.BuildQueryString(sendData));
181
182 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
183
184 SimpleRegionInfo rinfo = null;
185 if ((replyData != null) && (replyData["result"] != null))
186 {
187 if (replyData["result"] is Dictionary<string, object>)
188 rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]);
189 else
190 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received invalid response",
191 scopeID, regionID);
192 }
193 else
194 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response",
195 scopeID, regionID);
196
197 return rinfo;
198 }
199
200 public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y)
201 {
202 Dictionary<string, string> sendData = new Dictionary<string, string>();
203
204 sendData["SCOPEID"] = scopeID.ToString();
205 sendData["X"] = x.ToString();
206 sendData["Y"] = y.ToString();
207
208 sendData["METHOD"] = "get_region_by_position";
209
210 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
211 m_ServerURI + "/grid",
212 ServerUtils.BuildQueryString(sendData));
213
214 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
215
216 SimpleRegionInfo rinfo = null;
217 if ((replyData != null) && (replyData["result"] != null))
218 {
219 if (replyData["result"] is Dictionary<string, object>)
220 rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]);
221 else
222 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received invalid response",
223 scopeID, x, y);
224 }
225 else
226 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response",
227 scopeID, x, y);
228
229 return rinfo;
230 }
231
232 public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName)
233 {
234 Dictionary<string, string> sendData = new Dictionary<string, string>();
235
236 sendData["SCOPEID"] = scopeID.ToString();
237 sendData["NAME"] = regionName;
238
239 sendData["METHOD"] = "get_region_by_name";
240
241 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
242 m_ServerURI + "/grid",
243 ServerUtils.BuildQueryString(sendData));
244
245 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
246
247 SimpleRegionInfo rinfo = null;
248 if ((replyData != null) && (replyData["result"] != null))
249 {
250 if (replyData["result"] is Dictionary<string, object>)
251 rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]);
252 else
253 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received invalid response",
254 scopeID, regionName);
255 }
256 else
257 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response",
258 scopeID, regionName);
259
260 return rinfo;
261 }
262
263 public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber)
264 {
265 Dictionary<string, string> sendData = new Dictionary<string, string>();
266
267 sendData["SCOPEID"] = scopeID.ToString();
268 sendData["NAME"] = name;
269 sendData["MAX"] = maxNumber.ToString();
270
271 sendData["METHOD"] = "get_regions_by_name";
272
273 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
274 m_ServerURI + "/grid",
275 ServerUtils.BuildQueryString(sendData));
276
277 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
278
279 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
280 if (replyData != null)
281 {
282 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
283 foreach (object r in rinfosList)
284 {
285 if (r is Dictionary<string, object>)
286 {
287 SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r);
288 rinfos.Add(rinfo);
289 }
290 else
291 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received invalid response",
292 scopeID, name, maxNumber);
293 }
294 }
295 else
296 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response",
297 scopeID, name, maxNumber);
298
299 return rinfos;
300 }
301
302 public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
303 {
304 Dictionary<string, string> sendData = new Dictionary<string, string>();
305
306 sendData["SCOPEID"] = scopeID.ToString();
307 sendData["XMIN"] = xmin.ToString();
308 sendData["XMAX"] = xmax.ToString();
309 sendData["YMIN"] = ymin.ToString();
310 sendData["YMAX"] = ymax.ToString();
311
312 sendData["METHOD"] = "get_region_range";
313
314 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
315 m_ServerURI + "/grid",
316 ServerUtils.BuildQueryString(sendData));
317
318 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
319
320 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
321 if (replyData != null)
322 {
323 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
324 foreach (object r in rinfosList)
325 {
326 if (r is Dictionary<string, object>)
327 {
328 SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r);
329 rinfos.Add(rinfo);
330 }
331 else
332 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received invalid response",
333 scopeID, xmin, xmax, ymin, ymax);
334 }
335 }
336 else
337 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response",
338 scopeID, xmin, xmax, ymin, ymax);
339
340 return rinfos;
341 }
342
343 #endregion
344
345 }
346}
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 6aa1c4f..2229421 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -88,13 +88,18 @@ namespace OpenSim.Services.GridService
88 return m_Database.Delete(regionID); 88 return m_Database.Delete(regionID);
89 } 89 }
90 90
91 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, int x, int y) 91 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID)
92 { 92 {
93 List<RegionData> rdatas = m_Database.Get(x - 1, y - 1, x + 1, y + 1, scopeID);
94 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 93 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
95 foreach (RegionData rdata in rdatas) 94 RegionData region = m_Database.Get(regionID, scopeID);
96 rinfos.Add(RegionData2RegionInfo(rdata)); 95 if (region != null)
96 {
97 // Not really? Maybe?
98 List<RegionData> rdatas = m_Database.Get(region.posX - 1, region.posY - 1, region.posX + 1, region.posY + 1, scopeID);
99 foreach (RegionData rdata in rdatas)
100 rinfos.Add(RegionData2RegionInfo(rdata));
97 101
102 }
98 return rinfos; 103 return rinfos;
99 } 104 }
100 105
@@ -164,68 +169,20 @@ namespace OpenSim.Services.GridService
164 rdata.posX = (int)rinfo.RegionLocX; 169 rdata.posX = (int)rinfo.RegionLocX;
165 rdata.posY = (int)rinfo.RegionLocY; 170 rdata.posY = (int)rinfo.RegionLocY;
166 rdata.RegionID = rinfo.RegionID; 171 rdata.RegionID = rinfo.RegionID;
172 rdata.Data = rinfo.ToKeyValuePairs();
167 //rdata.RegionName = rinfo.RegionName; 173 //rdata.RegionName = rinfo.RegionName;
168 rdata.Data["external_ip_address"] = rinfo.ExternalEndPoint.Address.ToString();
169 rdata.Data["external_port"] = rinfo.ExternalEndPoint.Port.ToString();
170 rdata.Data["external_host_name"] = rinfo.ExternalHostName;
171 rdata.Data["http_port"] = rinfo.HttpPort.ToString();
172 rdata.Data["internal_ip_address"] = rinfo.InternalEndPoint.Address.ToString();
173 rdata.Data["internal_port"] = rinfo.InternalEndPoint.Port.ToString();
174 rdata.Data["alternate_ports"] = rinfo.m_allow_alternate_ports.ToString();
175 rdata.Data["server_uri"] = rinfo.ServerURI;
176 174
177 return rdata; 175 return rdata;
178 } 176 }
179 177
180 protected SimpleRegionInfo RegionData2RegionInfo(RegionData rdata) 178 protected SimpleRegionInfo RegionData2RegionInfo(RegionData rdata)
181 { 179 {
182 SimpleRegionInfo rinfo = new SimpleRegionInfo(); 180 SimpleRegionInfo rinfo = new SimpleRegionInfo(rdata.Data);
183 rinfo.RegionLocX = (uint)rdata.posX; 181 rinfo.RegionLocX = (uint)rdata.posX;
184 rinfo.RegionLocY = (uint)rdata.posY; 182 rinfo.RegionLocY = (uint)rdata.posY;
185 rinfo.RegionID = rdata.RegionID; 183 rinfo.RegionID = rdata.RegionID;
186 //rinfo.RegionName = rdata.RegionName; 184 //rinfo.RegionName = rdata.RegionName;
187 185
188 // Now for the variable data
189 if ((rdata.Data["external_ip_address"] != null) && (rdata.Data["external_port"] != null))
190 {
191 int port = 0;
192 Int32.TryParse((string)rdata.Data["external_port"], out port);
193 IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)rdata.Data["external_ip_address"]), port);
194 rinfo.ExternalEndPoint = ep;
195 }
196 else
197 rinfo.ExternalEndPoint = new IPEndPoint(new IPAddress(0), 0);
198
199 if (rdata.Data["external_host_name"] != null)
200 rinfo.ExternalHostName = (string)rdata.Data["external_host_name"] ;
201
202 if (rdata.Data["http_port"] != null)
203 {
204 UInt32 port = 0;
205 UInt32.TryParse((string)rdata.Data["http_port"], out port);
206 rinfo.HttpPort = port;
207 }
208
209 if ((rdata.Data["internal_ip_address"] != null) && (rdata.Data["internal_port"] != null))
210 {
211 int port = 0;
212 Int32.TryParse((string)rdata.Data["internal_port"], out port);
213 IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)rdata.Data["internal_ip_address"]), port);
214 rinfo.InternalEndPoint = ep;
215 }
216 else
217 rinfo.InternalEndPoint = new IPEndPoint(new IPAddress(0), 0);
218
219 if (rdata.Data["alternate_ports"] != null)
220 {
221 bool alts = false;
222 Boolean.TryParse((string)rdata.Data["alternate_ports"], out alts);
223 rinfo.m_allow_alternate_ports = alts;
224 }
225
226 if (rdata.Data["server_uri"] != null)
227 rinfo.ServerURI = (string)rdata.Data["server_uri"];
228
229 return rinfo; 186 return rinfo;
230 } 187 }
231 188
diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs
index 83ab9c1..8f6c524 100644
--- a/OpenSim/Services/Interfaces/IGridService.cs
+++ b/OpenSim/Services/Interfaces/IGridService.cs
@@ -55,7 +55,7 @@ namespace OpenSim.Services.Interfaces
55 /// <param name="x"></param> 55 /// <param name="x"></param>
56 /// <param name="y"></param> 56 /// <param name="y"></param>
57 /// <returns></returns> 57 /// <returns></returns>
58 List<SimpleRegionInfo> GetNeighbours(UUID scopeID, int x, int y); 58 List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID);
59 59
60 SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID); 60 SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID);
61 61