diff options
Diffstat (limited to 'OpenSim/Grid/MessagingServer/MessageService.cs')
-rw-r--r-- | OpenSim/Grid/MessagingServer/MessageService.cs | 299 |
1 files changed, 42 insertions, 257 deletions
diff --git a/OpenSim/Grid/MessagingServer/MessageService.cs b/OpenSim/Grid/MessagingServer/MessageService.cs index 36f8b91..75fb969 100644 --- a/OpenSim/Grid/MessagingServer/MessageService.cs +++ b/OpenSim/Grid/MessagingServer/MessageService.cs | |||
@@ -46,30 +46,53 @@ namespace OpenSim.Grid.MessagingServer | |||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
47 | 47 | ||
48 | private MessageServerConfig m_cfg; | 48 | private MessageServerConfig m_cfg; |
49 | private UserManager m_userManager; | 49 | private UserDataBaseService m_userDataBaseService; |
50 | 50 | ||
51 | // a dictionary of all current presences this server knows about | 51 | private IUGAIMCore m_messageCore; |
52 | private Dictionary<UUID, UserPresenceData> m_presences = new Dictionary<UUID,UserPresenceData>(); | ||
53 | 52 | ||
54 | // a dictionary of all current regions this server knows about | 53 | private IMessageUserServerService m_userServerModule; |
55 | private Dictionary<ulong, RegionProfileData> m_regionInfoCache = new Dictionary<ulong,RegionProfileData>(); | 54 | private IMessageRegionService m_regionModule; |
56 | 55 | ||
57 | private Timer reconnectTimer = new Timer(300000); // 5 mins | 56 | // a dictionary of all current presences this server knows about |
57 | private Dictionary<UUID, UserPresenceData> m_presences = new Dictionary<UUID,UserPresenceData>(); | ||
58 | 58 | ||
59 | public MessageService(MessageServerConfig cfg) | 59 | public MessageService(MessageServerConfig cfg, IUGAIMCore messageCore, UserDataBaseService userDataBaseService) |
60 | { | 60 | { |
61 | m_cfg = cfg; | 61 | m_cfg = cfg; |
62 | m_userManager = new UserManager(); | 62 | m_messageCore = messageCore; |
63 | |||
64 | m_userDataBaseService = userDataBaseService; | ||
65 | |||
66 | //??? | ||
63 | UserConfig uc = new UserConfig(); | 67 | UserConfig uc = new UserConfig(); |
64 | uc.DatabaseConnect = cfg.DatabaseConnect; | 68 | uc.DatabaseConnect = cfg.DatabaseConnect; |
65 | uc.DatabaseProvider = cfg.DatabaseProvider; | 69 | uc.DatabaseProvider = cfg.DatabaseProvider; |
70 | } | ||
66 | 71 | ||
67 | m_userManager.AddPlugin(cfg.DatabaseProvider, cfg.DatabaseConnect); | 72 | public void Initialise() |
73 | { | ||
74 | } | ||
75 | |||
76 | public void PostInitialise() | ||
77 | { | ||
78 | IMessageUserServerService messageUserServer; | ||
79 | if (m_messageCore.TryGet<IMessageUserServerService>(out messageUserServer)) | ||
80 | { | ||
81 | m_userServerModule = messageUserServer; | ||
82 | } | ||
68 | 83 | ||
69 | reconnectTimer.Elapsed += registerWithUserServer; | 84 | IMessageRegionService messageRegion; |
70 | reconnectTimer.Start(); | 85 | if (m_messageCore.TryGet<IMessageRegionService>(out messageRegion)) |
86 | { | ||
87 | m_regionModule = messageRegion; | ||
88 | } | ||
71 | } | 89 | } |
72 | 90 | ||
91 | public void RegisterHandlers() | ||
92 | { | ||
93 | //have these in separate method as some servers restart the http server and reregister all the handlers. | ||
94 | |||
95 | } | ||
73 | 96 | ||
74 | #region FriendList Methods | 97 | #region FriendList Methods |
75 | 98 | ||
@@ -107,7 +130,7 @@ namespace OpenSim.Grid.MessagingServer | |||
107 | /// <param name="receiver">We are sending the presence update to this user</param> | 130 | /// <param name="receiver">We are sending the presence update to this user</param> |
108 | private void enqueuePresenceUpdate(UserPresenceData talkingAbout, UserPresenceData receiver) | 131 | private void enqueuePresenceUpdate(UserPresenceData talkingAbout, UserPresenceData receiver) |
109 | { | 132 | { |
110 | UserAgentData p2Handle = m_userManager.GetUserAgentData(receiver.agentData.AgentID); | 133 | UserAgentData p2Handle = m_userDataBaseService.GetUserAgentData(receiver.agentData.AgentID); |
111 | if (p2Handle != null) | 134 | if (p2Handle != null) |
112 | { | 135 | { |
113 | if (receiver.lookupUserRegionYN) | 136 | if (receiver.lookupUserRegionYN) |
@@ -122,7 +145,7 @@ namespace OpenSim.Grid.MessagingServer | |||
122 | PresenceInformer friendlistupdater = new PresenceInformer(); | 145 | PresenceInformer friendlistupdater = new PresenceInformer(); |
123 | friendlistupdater.presence1 = talkingAbout; | 146 | friendlistupdater.presence1 = talkingAbout; |
124 | friendlistupdater.presence2 = receiver; | 147 | friendlistupdater.presence2 = receiver; |
125 | friendlistupdater.OnGetRegionData += GetRegionInfo; | 148 | friendlistupdater.OnGetRegionData += m_regionModule.GetRegionInfo; |
126 | friendlistupdater.OnDone += PresenceUpdateDone; | 149 | friendlistupdater.OnDone += PresenceUpdateDone; |
127 | WaitCallback cb = new WaitCallback(friendlistupdater.go); | 150 | WaitCallback cb = new WaitCallback(friendlistupdater.go); |
128 | ThreadPool.QueueUserWorkItem(cb); | 151 | ThreadPool.QueueUserWorkItem(cb); |
@@ -225,7 +248,7 @@ namespace OpenSim.Grid.MessagingServer | |||
225 | 248 | ||
226 | private void PresenceUpdateDone(PresenceInformer obj) | 249 | private void PresenceUpdateDone(PresenceInformer obj) |
227 | { | 250 | { |
228 | obj.OnGetRegionData -= GetRegionInfo; | 251 | obj.OnGetRegionData -= m_regionModule.GetRegionInfo; |
229 | obj.OnDone -= PresenceUpdateDone; | 252 | obj.OnDone -= PresenceUpdateDone; |
230 | } | 253 | } |
231 | 254 | ||
@@ -332,7 +355,7 @@ namespace OpenSim.Grid.MessagingServer | |||
332 | UserPresenceData up = new UserPresenceData(); | 355 | UserPresenceData up = new UserPresenceData(); |
333 | up.agentData = agentData; | 356 | up.agentData = agentData; |
334 | up.friendData = GetUserFriendList(agentData.AgentID); | 357 | up.friendData = GetUserFriendList(agentData.AgentID); |
335 | up.regionData = GetRegionInfo(regionHandle); | 358 | up.regionData = m_regionModule.GetRegionInfo(regionHandle); |
336 | up.OnlineYN = true; | 359 | up.OnlineYN = true; |
337 | up.lookupUserRegionYN = false; | 360 | up.lookupUserRegionYN = false; |
338 | ProcessFriendListSubscriptions(up); | 361 | ProcessFriendListSubscriptions(up); |
@@ -380,7 +403,7 @@ namespace OpenSim.Grid.MessagingServer | |||
380 | } | 403 | } |
381 | 404 | ||
382 | try { | 405 | try { |
383 | Dictionary<UUID, FriendRegionInfo> infos = m_userManager.GetFriendRegionInfos(uuids); | 406 | Dictionary<UUID, FriendRegionInfo> infos = m_userDataBaseService.GetFriendRegionInfos(uuids); |
384 | m_log.DebugFormat("[FRIEND]: Got {0} region entries back.", infos.Count); | 407 | m_log.DebugFormat("[FRIEND]: Got {0} region entries back.", infos.Count); |
385 | int count = 0; | 408 | int count = 0; |
386 | foreach (KeyValuePair<UUID, FriendRegionInfo> pair in infos) | 409 | foreach (KeyValuePair<UUID, FriendRegionInfo> pair in infos) |
@@ -402,251 +425,13 @@ namespace OpenSim.Grid.MessagingServer | |||
402 | } | 425 | } |
403 | } | 426 | } |
404 | 427 | ||
405 | #region regioninfo gathering | ||
406 | |||
407 | /// <summary> | ||
408 | /// Gets and caches a RegionInfo object from the gridserver based on regionhandle | ||
409 | /// if the regionhandle is already cached, use the cached values | ||
410 | /// Gets called by lots of threads!!!!! | ||
411 | /// </summary> | ||
412 | /// <param name="regionhandle">handle to the XY of the region we're looking for</param> | ||
413 | /// <returns>A RegionInfo object to stick in the presence info</returns> | ||
414 | public RegionProfileData GetRegionInfo(ulong regionhandle) | ||
415 | { | ||
416 | RegionProfileData regionInfo = null; | ||
417 | |||
418 | lock (m_regionInfoCache) | ||
419 | { | ||
420 | m_regionInfoCache.TryGetValue(regionhandle, out regionInfo); | ||
421 | } | ||
422 | |||
423 | if (regionInfo == null) // not found in cache | ||
424 | { | ||
425 | regionInfo = RequestRegionInfo(regionhandle); | ||
426 | |||
427 | if (regionInfo != null) // lookup was successful | ||
428 | { | ||
429 | lock (m_regionInfoCache) | ||
430 | { | ||
431 | m_regionInfoCache[regionhandle] = regionInfo; | ||
432 | } | ||
433 | } | ||
434 | } | ||
435 | |||
436 | return regionInfo; | ||
437 | } | ||
438 | |||
439 | public int ClearRegionCache() | ||
440 | { | ||
441 | int cachecount = 0; | ||
442 | |||
443 | lock (m_regionInfoCache) | ||
444 | { | ||
445 | cachecount = m_regionInfoCache.Count; | ||
446 | m_regionInfoCache.Clear(); | ||
447 | } | ||
448 | |||
449 | return cachecount; | ||
450 | } | ||
451 | |||
452 | /// <summary> | ||
453 | /// Get RegionProfileData from the GridServer. | ||
454 | /// We'll cache this information in GetRegionInfo and use it for presence updates | ||
455 | /// </summary> | ||
456 | /// <param name="regionHandle"></param> | ||
457 | /// <returns></returns> | ||
458 | public RegionProfileData RequestRegionInfo(ulong regionHandle) | ||
459 | { | ||
460 | RegionProfileData regionProfile = null; | ||
461 | try | ||
462 | { | ||
463 | Hashtable requestData = new Hashtable(); | ||
464 | requestData["region_handle"] = regionHandle.ToString(); | ||
465 | requestData["authkey"] = m_cfg.GridSendKey; | ||
466 | |||
467 | ArrayList SendParams = new ArrayList(); | ||
468 | SendParams.Add(requestData); | ||
469 | |||
470 | XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams); | ||
471 | |||
472 | XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000); | ||
473 | |||
474 | Hashtable responseData = (Hashtable)GridResp.Value; | ||
475 | |||
476 | if (responseData.ContainsKey("error")) | ||
477 | { | ||
478 | m_log.Error("[GRID]: error received from grid server" + responseData["error"]); | ||
479 | return null; | ||
480 | } | ||
481 | |||
482 | uint regX = Convert.ToUInt32((string)responseData["region_locx"]); | ||
483 | uint regY = Convert.ToUInt32((string)responseData["region_locy"]); | ||
484 | string internalIpStr = (string)responseData["sim_ip"]; | ||
485 | |||
486 | regionProfile = new RegionProfileData(); | ||
487 | regionProfile.httpPort = (uint)Convert.ToInt32((string)responseData["http_port"]); | ||
488 | regionProfile.httpServerURI = "http://" + internalIpStr + ":" + regionProfile.httpPort + "/"; | ||
489 | regionProfile.regionHandle = Utils.UIntsToLong((regX * Constants.RegionSize), (regY * Constants.RegionSize)); | ||
490 | regionProfile.regionLocX = regX; | ||
491 | regionProfile.regionLocY = regY; | ||
492 | |||
493 | regionProfile.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]); | ||
494 | regionProfile.UUID = new UUID((string)responseData["region_UUID"]); | ||
495 | regionProfile.regionName = (string)responseData["region_name"]; | ||
496 | } | ||
497 | catch (WebException) | ||
498 | { | ||
499 | m_log.Error("[GRID]: " + | ||
500 | "Region lookup failed for: " + regionHandle.ToString() + | ||
501 | " - Is the GridServer down?"); | ||
502 | } | ||
503 | |||
504 | return regionProfile; | ||
505 | } | ||
506 | |||
507 | public void registerWithUserServer(object sender, ElapsedEventArgs e) | ||
508 | { | ||
509 | registerWithUserServer(); | ||
510 | } | ||
511 | |||
512 | public bool registerWithUserServer () | ||
513 | { | ||
514 | Hashtable UserParams = new Hashtable(); | ||
515 | // Login / Authentication | ||
516 | |||
517 | if (m_cfg.HttpSSL) | ||
518 | { | ||
519 | UserParams["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
520 | } | ||
521 | else | ||
522 | { | ||
523 | UserParams["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
524 | } | ||
525 | |||
526 | UserParams["recvkey"] = m_cfg.UserRecvKey; | ||
527 | UserParams["sendkey"] = m_cfg.UserRecvKey; | ||
528 | |||
529 | // Package into an XMLRPC Request | ||
530 | ArrayList SendParams = new ArrayList(); | ||
531 | SendParams.Add(UserParams); | ||
532 | |||
533 | bool success = true; | ||
534 | string[] servers = m_cfg.UserServerURL.Split(' '); | ||
535 | |||
536 | foreach (string srv in servers) | ||
537 | { | ||
538 | // Send Request | ||
539 | try | ||
540 | { | ||
541 | XmlRpcRequest UserReq = new XmlRpcRequest("register_messageserver", SendParams); | ||
542 | XmlRpcResponse UserResp = UserReq.Send(srv, 16000); | ||
543 | |||
544 | // Process Response | ||
545 | Hashtable GridRespData = (Hashtable)UserResp.Value; | ||
546 | // if we got a response, we were successful | ||
547 | if (!GridRespData.ContainsKey("responsestring")) | ||
548 | success = false; | ||
549 | else | ||
550 | m_log.InfoFormat("[SERVER] Registered with {0}", srv); | ||
551 | } | ||
552 | catch | ||
553 | { | ||
554 | m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv); | ||
555 | success = false; | ||
556 | } | ||
557 | } | ||
558 | return success; | ||
559 | } | ||
560 | |||
561 | public bool deregisterWithUserServer() | ||
562 | { | ||
563 | Hashtable request = new Hashtable(); | ||
564 | |||
565 | return SendToUserServer(request, "deregister_messageserver"); | ||
566 | } | ||
567 | |||
568 | public bool SendToUserServer(Hashtable request, string method) | ||
569 | { | ||
570 | // Login / Authentication | ||
571 | |||
572 | if (m_cfg.HttpSSL) | ||
573 | { | ||
574 | request["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
575 | } | ||
576 | else | ||
577 | { | ||
578 | request["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
579 | } | ||
580 | |||
581 | request["recvkey"] = m_cfg.UserRecvKey; | ||
582 | request["sendkey"] = m_cfg.UserRecvKey; | ||
583 | |||
584 | // Package into an XMLRPC Request | ||
585 | ArrayList SendParams = new ArrayList(); | ||
586 | SendParams.Add(request); | ||
587 | |||
588 | bool success = true; | ||
589 | string[] servers = m_cfg.UserServerURL.Split(' '); | ||
590 | |||
591 | // Send Request | ||
592 | foreach (string srv in servers) | ||
593 | { | ||
594 | try | ||
595 | { | ||
596 | XmlRpcRequest UserReq = new XmlRpcRequest(method, SendParams); | ||
597 | XmlRpcResponse UserResp = UserReq.Send(m_cfg.UserServerURL, 16000); | ||
598 | // Process Response | ||
599 | Hashtable UserRespData = (Hashtable)UserResp.Value; | ||
600 | // if we got a response, we were successful | ||
601 | if (!UserRespData.ContainsKey("responsestring")) | ||
602 | success = false; | ||
603 | } | ||
604 | catch | ||
605 | { | ||
606 | m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv); | ||
607 | success = false; | ||
608 | } | ||
609 | } | ||
610 | return success; | ||
611 | } | ||
612 | |||
613 | #endregion | ||
614 | |||
615 | public XmlRpcResponse RegionStartup(XmlRpcRequest request) | ||
616 | { | ||
617 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
618 | Hashtable result = new Hashtable(); | ||
619 | result["success"] = "FALSE"; | ||
620 | |||
621 | if (SendToUserServer(requestData, "region_startup")) | ||
622 | result["success"] = "TRUE"; | ||
623 | |||
624 | XmlRpcResponse response = new XmlRpcResponse(); | ||
625 | response.Value = result; | ||
626 | return response; | ||
627 | } | ||
628 | |||
629 | public XmlRpcResponse RegionShutdown(XmlRpcRequest request) | ||
630 | { | ||
631 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
632 | Hashtable result = new Hashtable(); | ||
633 | result["success"] = "FALSE"; | ||
634 | |||
635 | if (SendToUserServer(requestData, "region_shutdown")) | ||
636 | result["success"] = "TRUE"; | ||
637 | |||
638 | XmlRpcResponse response = new XmlRpcResponse(); | ||
639 | response.Value = result; | ||
640 | return response; | ||
641 | } | ||
642 | |||
643 | public XmlRpcResponse AgentLocation(XmlRpcRequest request) | 428 | public XmlRpcResponse AgentLocation(XmlRpcRequest request) |
644 | { | 429 | { |
645 | Hashtable requestData = (Hashtable)request.Params[0]; | 430 | Hashtable requestData = (Hashtable)request.Params[0]; |
646 | Hashtable result = new Hashtable(); | 431 | Hashtable result = new Hashtable(); |
647 | result["success"] = "FALSE"; | 432 | result["success"] = "FALSE"; |
648 | 433 | ||
649 | if (SendToUserServer(requestData, "agent_location")) | 434 | if (m_userServerModule.SendToUserServer(requestData, "agent_location")) |
650 | result["success"] = "TRUE"; | 435 | result["success"] = "TRUE"; |
651 | 436 | ||
652 | 437 | ||
@@ -661,7 +446,7 @@ namespace OpenSim.Grid.MessagingServer | |||
661 | Hashtable result = new Hashtable(); | 446 | Hashtable result = new Hashtable(); |
662 | result["success"] = "FALSE"; | 447 | result["success"] = "FALSE"; |
663 | 448 | ||
664 | if (SendToUserServer(requestData, "agent_leaving")) | 449 | if (m_userServerModule.SendToUserServer(requestData, "agent_leaving")) |
665 | result["success"] = "TRUE"; | 450 | result["success"] = "TRUE"; |
666 | 451 | ||
667 | XmlRpcResponse response = new XmlRpcResponse(); | 452 | XmlRpcResponse response = new XmlRpcResponse(); |
@@ -699,4 +484,4 @@ namespace OpenSim.Grid.MessagingServer | |||
699 | return response; | 484 | return response; |
700 | } | 485 | } |
701 | } | 486 | } |
702 | } | 487 | } \ No newline at end of file |