aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-05-12 22:00:33 +0000
committerJustin Clarke Casey2008-05-12 22:00:33 +0000
commitc8b59f7a317de767897b2ee4c44f55d9ed45575d (patch)
tree45a90c3373eb3d6e7cf257ef1bb86ba6e268220a /OpenSim
parent* Committing sample IClientAPI2.cs (diff)
downloadopensim-SC-c8b59f7a317de767897b2ee4c44f55d9ed45575d.zip
opensim-SC-c8b59f7a317de767897b2ee4c44f55d9ed45575d.tar.gz
opensim-SC-c8b59f7a317de767897b2ee4c44f55d9ed45575d.tar.bz2
opensim-SC-c8b59f7a317de767897b2ee4c44f55d9ed45575d.tar.xz
* Refactor: Creating grid login exceptions to try and break up a large method.
* This in preparation for further login validation to check that the region logging in is properly contactable. * Also increase verbosity of some error messages
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Grid/GridServer/GridManager.cs180
1 files changed, 109 insertions, 71 deletions
diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs
index 284ac0c..2bb26cf 100644
--- a/OpenSim/Grid/GridServer/GridManager.cs
+++ b/OpenSim/Grid/GridServer/GridManager.cs
@@ -248,10 +248,18 @@ namespace OpenSim.Grid.GridServer
248 /// </summary> 248 /// </summary>
249 /// <param name="sim"></param> 249 /// <param name="sim"></param>
250 /// <returns></returns> 250 /// <returns></returns>
251 protected virtual bool ValidateOverwrite(RegionProfileData sim, RegionProfileData existingSim) 251 protected virtual void ValidateOverwrite(RegionProfileData sim, RegionProfileData existingSim)
252 { 252 {
253 return (existingSim.regionRecvKey == sim.regionRecvKey && 253 if (!(existingSim.regionRecvKey == sim.regionRecvKey && existingSim.regionSendKey == sim.regionSendKey))
254 existingSim.regionSendKey == sim.regionSendKey); 254 {
255 throw new LoginException(
256 String.Format(
257 "Authentication failed when trying to login existing region {0} at location {1} {2} currently occupied by {3}"
258 + " with the region's send key {4} (expected {5}) and the region's receive key {6} (expected {7})",
259 sim.regionName, sim.regionLocX, sim.regionLocY, existingSim.regionName,
260 sim.regionSendKey, existingSim.regionSendKey, sim.regionRecvKey, existingSim.regionRecvKey),
261 "The keys required to login your region did not match the grid server keys. Please check your grid send and receive keys.");
262 }
255 } 263 }
256 264
257 /// <summary> 265 /// <summary>
@@ -260,15 +268,30 @@ namespace OpenSim.Grid.GridServer
260 /// Currently, this means checking that the keys passed in by the new region 268 /// Currently, this means checking that the keys passed in by the new region
261 /// match those in the grid server's configuration. 269 /// match those in the grid server's configuration.
262 /// </summary> 270 /// </summary>
271 ///
263 /// <param name="sim"></param> 272 /// <param name="sim"></param>
264 /// <returns></returns> 273 /// <exception cref="LoginException">Thrown if region login failed</exception>
265 protected virtual bool ValidateNewRegion(RegionProfileData sim) 274 protected virtual void ValidateNewRegion(RegionProfileData sim)
266 { 275 {
267 return (sim.regionRecvKey == Config.SimSendKey && 276 if (!(sim.regionRecvKey == Config.SimSendKey && sim.regionSendKey == Config.SimRecvKey))
268 sim.regionSendKey == Config.SimRecvKey); 277 {
278 throw new LoginException(
279 String.Format(
280 "Authentication failed when trying to login new region {0} at location {1} {2}"
281 + " with the region's send key {3} (expected {4}) and the region's receive key {5} (expected {6})",
282 sim.regionName, sim.regionLocX, sim.regionLocY,
283 sim.regionSendKey, Config.SimRecvKey, sim.regionRecvKey, Config.SimSendKey),
284 "The keys required to login your region did not match your existing region keys. Please check your grid send and receive keys.");
285 }
286
269 } 287 }
270 288
271 private static XmlRpcResponse ErrorResponse(string error) 289 /// <summary>
290 /// Construct an XMLRPC error response
291 /// </summary>
292 /// <param name="error"></param>
293 /// <returns></returns>
294 public static XmlRpcResponse ErrorResponse(string error)
272 { 295 {
273 XmlRpcResponse errorResponse = new XmlRpcResponse(); 296 XmlRpcResponse errorResponse = new XmlRpcResponse();
274 Hashtable errorResponseData = new Hashtable(); 297 Hashtable errorResponseData = new Hashtable();
@@ -280,7 +303,7 @@ namespace OpenSim.Grid.GridServer
280 /// <summary> 303 /// <summary>
281 /// Performed when a region connects to the grid server initially. 304 /// Performed when a region connects to the grid server initially.
282 /// </summary> 305 /// </summary>
283 /// <param name="request">The XMLRPC Request</param> 306 /// <param name="request">The XML RPC Request</param>
284 /// <returns>Startup parameters</returns> 307 /// <returns>Startup parameters</returns>
285 public XmlRpcResponse XmlRpcSimulatorLoginMethod(XmlRpcRequest request) 308 public XmlRpcResponse XmlRpcSimulatorLoginMethod(XmlRpcRequest request)
286 { 309 {
@@ -310,86 +333,72 @@ namespace OpenSim.Grid.GridServer
310 333
311 existingSim = GetRegion(sim.regionHandle); 334 existingSim = GetRegion(sim.regionHandle);
312 335
336
313 if (existingSim == null || existingSim.UUID == sim.UUID || sim.UUID != sim.originUUID) 337 if (existingSim == null || existingSim.UUID == sim.UUID || sim.UUID != sim.originUUID)
314 { 338 {
315 bool validated; 339 try
316
317 if (existingSim == null)
318 { 340 {
319 validated = ValidateNewRegion(sim); 341 if (existingSim == null)
342 {
343 ValidateNewRegion(sim);
344 }
345 else
346 {
347 ValidateOverwrite(sim, existingSim);
348 }
320 } 349 }
321 else 350 catch (LoginException e)
322 { 351 {
323 validated = ValidateOverwrite(sim, existingSim); 352 m_log.WarnFormat("[LOGIN END]: {0}", e.Message);
353
354 return e.XmlRpcErrorResponse;
324 } 355 }
325 356
326 if (validated) 357 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
327 { 358 {
328 foreach (KeyValuePair<string, IGridData> kvp in _plugins) 359 try
329 { 360 {
330 try 361 DataResponse insertResponse;
362
363 if( existingSim == null )
331 { 364 {
332 DataResponse insertResponse; 365 insertResponse = kvp.Value.AddProfile(sim);
333
334 if( existingSim == null )
335 {
336 insertResponse = kvp.Value.AddProfile(sim);
337 }
338 else
339 {
340 insertResponse = kvp.Value.UpdateProfile(sim);
341 }
342
343 switch (insertResponse)
344 {
345 case DataResponse.RESPONSE_OK:
346 m_log.Info("[LOGIN END]: " + (existingSim == null ? "New" : "Existing") + " sim login successful: " + sim.regionName);
347 break;
348 case DataResponse.RESPONSE_ERROR:
349 m_log.Warn("[LOGIN END]: Sim login failed (Error): " + sim.regionName);
350 break;
351 case DataResponse.RESPONSE_INVALIDCREDENTIALS:
352 m_log.Warn("[LOGIN END]: " +
353 "Sim login failed (Invalid Credentials): " + sim.regionName);
354 break;
355 case DataResponse.RESPONSE_AUTHREQUIRED:
356 m_log.Warn("[LOGIN END]: " +
357 "Sim login failed (Authentication Required): " +
358 sim.regionName);
359 break;
360 }
361 } 366 }
362 catch (Exception e) 367 else
363 { 368 {
364 m_log.Warn("[LOGIN END]: " + 369 insertResponse = kvp.Value.UpdateProfile(sim);
365 "Unable to login region " + sim.UUID.ToString() + " via " + kvp.Key);
366 m_log.Warn("[LOGIN END]: " + e.ToString());
367 } 370 }
368 }
369 371
370 XmlRpcResponse response = CreateLoginResponse(sim); 372 switch (insertResponse)
371 373 {
372 return response; 374 case DataResponse.RESPONSE_OK:
373 } 375 m_log.Info("[LOGIN END]: " + (existingSim == null ? "New" : "Existing") + " sim login successful: " + sim.regionName);
374 else 376 break;
375 { 377 case DataResponse.RESPONSE_ERROR:
376 if (existingSim == null) 378 m_log.Warn("[LOGIN END]: Sim login failed (Error): " + sim.regionName);
377 { 379 break;
378 m_log.WarnFormat( 380 case DataResponse.RESPONSE_INVALIDCREDENTIALS:
379 "[LOGIN END]: Authentication failed when trying to login new region {0} at location {1} {2}" 381 m_log.Warn("[LOGIN END]: " +
380 + " with TheSim.regionSendKey {3} (expected {4}) and TheSim.regionRecvKey {5} (expected {6})", 382 "Sim login failed (Invalid Credentials): " + sim.regionName);
381 sim.regionName, sim.regionLocX, sim.regionLocY, 383 break;
382 sim.regionSendKey, Config.SimRecvKey, sim.regionRecvKey, Config.SimSendKey); 384 case DataResponse.RESPONSE_AUTHREQUIRED:
385 m_log.Warn("[LOGIN END]: " +
386 "Sim login failed (Authentication Required): " +
387 sim.regionName);
388 break;
389 }
383 } 390 }
384 else 391 catch (Exception e)
385 { 392 {
386 m_log.Warn("[LOGIN END]: Authentication failed when trying to login region " + sim.regionName + 393 m_log.Warn("[LOGIN END]: " +
387 " at location " + sim.regionLocX + 394 "Unable to login region " + sim.UUID.ToString() + " via " + kvp.Key);
388 " " + sim.regionLocY + " currently occupied by " + existingSim.regionName); 395 m_log.Warn("[LOGIN END]: " + e.ToString());
389 } 396 }
390
391 return ErrorResponse("The key required to login your region did not match. Please check your grid send and receive keys.");
392 } 397 }
398
399 XmlRpcResponse response = CreateLoginResponse(sim);
400
401 return response;
393 } 402 }
394 else 403 else
395 { 404 {
@@ -1065,4 +1074,33 @@ namespace OpenSim.Grid.GridServer
1065 return response; 1074 return response;
1066 } 1075 }
1067 } 1076 }
1077
1078 /// <summary>
1079 /// Exception generated when a simulator fails to login to the grid
1080 /// </summary>
1081 public class LoginException : Exception
1082 {
1083 /// <summary>
1084 /// Return an XmlRpcResponse version of the exception message suitable for sending to a client
1085 /// </summary>
1086 /// <param name="message"></param>
1087 /// <param name="xmlRpcMessage"></param>
1088 public XmlRpcResponse XmlRpcErrorResponse
1089 {
1090 get { return m_xmlRpcErrorResponse; }
1091 }
1092 private XmlRpcResponse m_xmlRpcErrorResponse;
1093
1094 public LoginException(string message, string xmlRpcMessage) : base(message)
1095 {
1096 // FIXME: Might be neater to refactor and put the method inside here
1097 m_xmlRpcErrorResponse = GridManager.ErrorResponse(xmlRpcMessage);
1098 }
1099
1100 public LoginException(string message, string xmlRpcMessage, Exception e) : base(message, e)
1101 {
1102 // FIXME: Might be neater to refactor and put the method inside here
1103 m_xmlRpcErrorResponse = GridManager.ErrorResponse(xmlRpcMessage);
1104 }
1105 }
1068} 1106}