diff options
Diffstat (limited to 'OpenSim/Services/HypergridService/UserAgentService.cs')
-rw-r--r-- | OpenSim/Services/HypergridService/UserAgentService.cs | 208 |
1 files changed, 119 insertions, 89 deletions
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs index a6b5fc2..b414aca 100644 --- a/OpenSim/Services/HypergridService/UserAgentService.cs +++ b/OpenSim/Services/HypergridService/UserAgentService.cs | |||
@@ -30,6 +30,7 @@ using System.Collections.Generic; | |||
30 | using System.Net; | 30 | using System.Net; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | 32 | ||
33 | using OpenSim.Data; | ||
33 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
34 | using OpenSim.Services.Connectors.Friends; | 35 | using OpenSim.Services.Connectors.Friends; |
35 | using OpenSim.Services.Connectors.Hypergrid; | 36 | using OpenSim.Services.Connectors.Hypergrid; |
@@ -50,14 +51,14 @@ namespace OpenSim.Services.HypergridService | |||
50 | /// needs to do it for them. | 51 | /// needs to do it for them. |
51 | /// Once we have better clients, this shouldn't be needed. | 52 | /// Once we have better clients, this shouldn't be needed. |
52 | /// </summary> | 53 | /// </summary> |
53 | public class UserAgentService : IUserAgentService | 54 | public class UserAgentService : UserAgentServiceBase, IUserAgentService |
54 | { | 55 | { |
55 | private static readonly ILog m_log = | 56 | private static readonly ILog m_log = |
56 | LogManager.GetLogger( | 57 | LogManager.GetLogger( |
57 | MethodBase.GetCurrentMethod().DeclaringType); | 58 | MethodBase.GetCurrentMethod().DeclaringType); |
58 | 59 | ||
59 | // This will need to go into a DB table | 60 | // This will need to go into a DB table |
60 | static Dictionary<UUID, TravelingAgentInfo> m_TravelingAgents = new Dictionary<UUID, TravelingAgentInfo>(); | 61 | //static Dictionary<UUID, TravelingAgentInfo> m_Database = new Dictionary<UUID, TravelingAgentInfo>(); |
61 | 62 | ||
62 | static bool m_Initialized = false; | 63 | static bool m_Initialized = false; |
63 | 64 | ||
@@ -86,6 +87,7 @@ namespace OpenSim.Services.HypergridService | |||
86 | } | 87 | } |
87 | 88 | ||
88 | public UserAgentService(IConfigSource config, IFriendsSimConnector friendsConnector) | 89 | public UserAgentService(IConfigSource config, IFriendsSimConnector friendsConnector) |
90 | : base(config) | ||
89 | { | 91 | { |
90 | // Let's set this always, because we don't know the sequence | 92 | // Let's set this always, because we don't know the sequence |
91 | // of instantiations | 93 | // of instantiations |
@@ -146,6 +148,9 @@ namespace OpenSim.Services.HypergridService | |||
146 | if (!m_GridName.EndsWith("/")) | 148 | if (!m_GridName.EndsWith("/")) |
147 | m_GridName = m_GridName + "/"; | 149 | m_GridName = m_GridName + "/"; |
148 | 150 | ||
151 | // Finally some cleanup | ||
152 | m_Database.DeleteOld(); | ||
153 | |||
149 | } | 154 | } |
150 | } | 155 | } |
151 | 156 | ||
@@ -260,7 +265,8 @@ namespace OpenSim.Services.HypergridService | |||
260 | 265 | ||
261 | // Generate a new service session | 266 | // Generate a new service session |
262 | agentCircuit.ServiceSessionID = region.ServerURI + ";" + UUID.Random(); | 267 | agentCircuit.ServiceSessionID = region.ServerURI + ";" + UUID.Random(); |
263 | TravelingAgentInfo old = UpdateTravelInfo(agentCircuit, region); | 268 | TravelingAgentInfo old = null; |
269 | TravelingAgentInfo travel = CreateTravelInfo(agentCircuit, region, fromLogin, out old); | ||
264 | 270 | ||
265 | bool success = false; | 271 | bool success = false; |
266 | string myExternalIP = string.Empty; | 272 | string myExternalIP = string.Empty; |
@@ -282,23 +288,21 @@ namespace OpenSim.Services.HypergridService | |||
282 | m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}", | 288 | m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}", |
283 | agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason); | 289 | agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason); |
284 | 290 | ||
285 | // restore the old travel info | 291 | if (old != null) |
286 | lock (m_TravelingAgents) | 292 | StoreTravelInfo(old); |
287 | { | 293 | else |
288 | if (old == null) | 294 | m_Database.Delete(agentCircuit.SessionID); |
289 | m_TravelingAgents.Remove(agentCircuit.SessionID); | ||
290 | else | ||
291 | m_TravelingAgents[agentCircuit.SessionID] = old; | ||
292 | } | ||
293 | 295 | ||
294 | return false; | 296 | return false; |
295 | } | 297 | } |
296 | 298 | ||
299 | // Everything is ok | ||
300 | |||
301 | // Update the perceived IP Address of our grid | ||
297 | m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP); | 302 | m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP); |
298 | // else set the IP addresses associated with this client | 303 | travel.MyIpAddress = myExternalIP; |
299 | if (fromLogin) | 304 | |
300 | m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = agentCircuit.IPAddress; | 305 | StoreTravelInfo(travel); |
301 | m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP; | ||
302 | 306 | ||
303 | return true; | 307 | return true; |
304 | } | 308 | } |
@@ -309,57 +313,39 @@ namespace OpenSim.Services.HypergridService | |||
309 | return LoginAgentToGrid(agentCircuit, gatekeeper, finalDestination, false, out reason); | 313 | return LoginAgentToGrid(agentCircuit, gatekeeper, finalDestination, false, out reason); |
310 | } | 314 | } |
311 | 315 | ||
312 | private void SetClientIP(UUID sessionID, string ip) | 316 | TravelingAgentInfo CreateTravelInfo(AgentCircuitData agentCircuit, GridRegion region, bool fromLogin, out TravelingAgentInfo existing) |
313 | { | 317 | { |
314 | if (m_TravelingAgents.ContainsKey(sessionID)) | 318 | HGTravelingData hgt = m_Database.Get(agentCircuit.SessionID); |
315 | { | 319 | existing = null; |
316 | m_log.DebugFormat("[USER AGENT SERVICE]: Setting IP {0} for session {1}", ip, sessionID); | ||
317 | m_TravelingAgents[sessionID].ClientIPAddress = ip; | ||
318 | } | ||
319 | } | ||
320 | 320 | ||
321 | TravelingAgentInfo UpdateTravelInfo(AgentCircuitData agentCircuit, GridRegion region) | 321 | if (hgt != null) |
322 | { | ||
323 | TravelingAgentInfo travel = new TravelingAgentInfo(); | ||
324 | TravelingAgentInfo old = null; | ||
325 | lock (m_TravelingAgents) | ||
326 | { | 322 | { |
327 | if (m_TravelingAgents.ContainsKey(agentCircuit.SessionID)) | 323 | // Very important! Override whatever this agent comes with. |
328 | { | 324 | // UserAgentService always sets the IP for every new agent |
329 | // Very important! Override whatever this agent comes with. | 325 | // with the original IP address. |
330 | // UserAgentService always sets the IP for every new agent | 326 | existing = new TravelingAgentInfo(hgt); |
331 | // with the original IP address. | 327 | agentCircuit.IPAddress = existing.ClientIPAddress; |
332 | agentCircuit.IPAddress = m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress; | ||
333 | |||
334 | old = m_TravelingAgents[agentCircuit.SessionID]; | ||
335 | } | ||
336 | |||
337 | m_TravelingAgents[agentCircuit.SessionID] = travel; | ||
338 | } | 328 | } |
329 | |||
330 | TravelingAgentInfo travel = new TravelingAgentInfo(existing); | ||
331 | travel.SessionID = agentCircuit.SessionID; | ||
339 | travel.UserID = agentCircuit.AgentID; | 332 | travel.UserID = agentCircuit.AgentID; |
340 | travel.GridExternalName = region.ServerURI; | 333 | travel.GridExternalName = region.ServerURI; |
341 | travel.ServiceToken = agentCircuit.ServiceSessionID; | 334 | travel.ServiceToken = agentCircuit.ServiceSessionID; |
342 | if (old != null) | ||
343 | travel.ClientIPAddress = old.ClientIPAddress; | ||
344 | 335 | ||
345 | return old; | 336 | if (fromLogin) |
337 | travel.ClientIPAddress = agentCircuit.IPAddress; | ||
338 | |||
339 | StoreTravelInfo(travel); | ||
340 | |||
341 | return travel; | ||
346 | } | 342 | } |
347 | 343 | ||
348 | public void LogoutAgent(UUID userID, UUID sessionID) | 344 | public void LogoutAgent(UUID userID, UUID sessionID) |
349 | { | 345 | { |
350 | m_log.DebugFormat("[USER AGENT SERVICE]: User {0} logged out", userID); | 346 | m_log.DebugFormat("[USER AGENT SERVICE]: User {0} logged out", userID); |
351 | 347 | ||
352 | lock (m_TravelingAgents) | 348 | m_Database.Delete(sessionID); |
353 | { | ||
354 | List<UUID> travels = new List<UUID>(); | ||
355 | foreach (KeyValuePair<UUID, TravelingAgentInfo> kvp in m_TravelingAgents) | ||
356 | if (kvp.Value == null) // do some clean up | ||
357 | travels.Add(kvp.Key); | ||
358 | else if (kvp.Value.UserID == userID) | ||
359 | travels.Add(kvp.Key); | ||
360 | foreach (UUID session in travels) | ||
361 | m_TravelingAgents.Remove(session); | ||
362 | } | ||
363 | 349 | ||
364 | GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(userID.ToString()); | 350 | GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(userID.ToString()); |
365 | if (guinfo != null) | 351 | if (guinfo != null) |
@@ -369,10 +355,11 @@ namespace OpenSim.Services.HypergridService | |||
369 | // We need to prevent foreign users with the same UUID as a local user | 355 | // We need to prevent foreign users with the same UUID as a local user |
370 | public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName) | 356 | public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName) |
371 | { | 357 | { |
372 | if (!m_TravelingAgents.ContainsKey(sessionID)) | 358 | HGTravelingData hgt = m_Database.Get(sessionID); |
359 | if (hgt == null) | ||
373 | return false; | 360 | return false; |
374 | 361 | ||
375 | TravelingAgentInfo travel = m_TravelingAgents[sessionID]; | 362 | TravelingAgentInfo travel = new TravelingAgentInfo(hgt); |
376 | 363 | ||
377 | return travel.GridExternalName.ToLower() == thisGridExternalName.ToLower(); | 364 | return travel.GridExternalName.ToLower() == thisGridExternalName.ToLower(); |
378 | } | 365 | } |
@@ -385,29 +372,32 @@ namespace OpenSim.Services.HypergridService | |||
385 | m_log.DebugFormat("[USER AGENT SERVICE]: Verifying Client session {0} with reported IP {1}.", | 372 | m_log.DebugFormat("[USER AGENT SERVICE]: Verifying Client session {0} with reported IP {1}.", |
386 | sessionID, reportedIP); | 373 | sessionID, reportedIP); |
387 | 374 | ||
388 | if (m_TravelingAgents.ContainsKey(sessionID)) | 375 | HGTravelingData hgt = m_Database.Get(sessionID); |
389 | { | 376 | if (hgt == null) |
390 | m_log.DebugFormat("[USER AGENT SERVICE]: Comparing with login IP {0} and MyIP {1}", | 377 | return false; |
391 | m_TravelingAgents[sessionID].ClientIPAddress, m_TravelingAgents[sessionID].MyIpAddress); | ||
392 | 378 | ||
393 | return m_TravelingAgents[sessionID].ClientIPAddress == reportedIP || | 379 | TravelingAgentInfo travel = new TravelingAgentInfo(hgt); |
394 | m_TravelingAgents[sessionID].MyIpAddress == reportedIP; // NATed | ||
395 | } | ||
396 | 380 | ||
397 | return false; | 381 | bool result = travel.ClientIPAddress == reportedIP || travel.MyIpAddress == reportedIP; // NATed |
382 | |||
383 | m_log.DebugFormat("[USER AGENT SERVICE]: Comparing {0} with login IP {1} and MyIP {1}; result is {3}", | ||
384 | reportedIP, travel.ClientIPAddress, travel.MyIpAddress, result); | ||
385 | |||
386 | return result; | ||
398 | } | 387 | } |
399 | 388 | ||
400 | public bool VerifyAgent(UUID sessionID, string token) | 389 | public bool VerifyAgent(UUID sessionID, string token) |
401 | { | 390 | { |
402 | if (m_TravelingAgents.ContainsKey(sessionID)) | 391 | HGTravelingData hgt = m_Database.Get(sessionID); |
392 | if (hgt == null) | ||
403 | { | 393 | { |
404 | m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, m_TravelingAgents[sessionID].ServiceToken); | 394 | m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID); |
405 | return m_TravelingAgents[sessionID].ServiceToken == token; | 395 | return false; |
406 | } | 396 | } |
407 | 397 | ||
408 | m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID); | 398 | TravelingAgentInfo travel = new TravelingAgentInfo(hgt); |
409 | 399 | m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, travel.ServiceToken); | |
410 | return false; | 400 | return travel.ServiceToken == token; |
411 | } | 401 | } |
412 | 402 | ||
413 | [Obsolete] | 403 | [Obsolete] |
@@ -470,17 +460,17 @@ namespace OpenSim.Services.HypergridService | |||
470 | } | 460 | } |
471 | } | 461 | } |
472 | 462 | ||
473 | // Lastly, let's notify the rest who may be online somewhere else | 463 | //// Lastly, let's notify the rest who may be online somewhere else |
474 | foreach (string user in usersToBeNotified) | 464 | //foreach (string user in usersToBeNotified) |
475 | { | 465 | //{ |
476 | UUID id = new UUID(user); | 466 | // UUID id = new UUID(user); |
477 | if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName) | 467 | // if (m_Database.ContainsKey(id) && m_Database[id].GridExternalName != m_GridName) |
478 | { | 468 | // { |
479 | string url = m_TravelingAgents[id].GridExternalName; | 469 | // string url = m_Database[id].GridExternalName; |
480 | // forward | 470 | // // forward |
481 | m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url); | 471 | // m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url); |
482 | } | 472 | // } |
483 | } | 473 | //} |
484 | 474 | ||
485 | // and finally, let's send the online friends | 475 | // and finally, let's send the online friends |
486 | if (online) | 476 | if (online) |
@@ -607,16 +597,13 @@ namespace OpenSim.Services.HypergridService | |||
607 | 597 | ||
608 | public string LocateUser(UUID userID) | 598 | public string LocateUser(UUID userID) |
609 | { | 599 | { |
610 | foreach (TravelingAgentInfo t in m_TravelingAgents.Values) | 600 | HGTravelingData[] hgts = m_Database.GetSessions(userID); |
611 | { | 601 | if (hgts == null) |
612 | if (t == null) | 602 | return string.Empty; |
613 | { | 603 | |
614 | m_log.ErrorFormat("[USER AGENT SERVICE]: Oops! Null TravelingAgentInfo. Please report this on mantis"); | 604 | foreach (HGTravelingData t in hgts) |
615 | continue; | 605 | if (t.Data.ContainsKey("GridExternalName") && !m_GridName.Equals(t.Data["GridExternalName"])) |
616 | } | 606 | return t.Data["GridExternalName"]; |
617 | if (t.UserID == userID && !m_GridName.Equals(t.GridExternalName)) | ||
618 | return t.GridExternalName; | ||
619 | } | ||
620 | 607 | ||
621 | return string.Empty; | 608 | return string.Empty; |
622 | } | 609 | } |
@@ -687,17 +674,60 @@ namespace OpenSim.Services.HypergridService | |||
687 | return exception; | 674 | return exception; |
688 | } | 675 | } |
689 | 676 | ||
677 | private void StoreTravelInfo(TravelingAgentInfo travel) | ||
678 | { | ||
679 | if (travel == null) | ||
680 | return; | ||
681 | |||
682 | HGTravelingData hgt = new HGTravelingData(); | ||
683 | hgt.SessionID = travel.SessionID; | ||
684 | hgt.UserID = travel.UserID; | ||
685 | hgt.Data = new Dictionary<string, string>(); | ||
686 | hgt.Data["GridExternalName"] = travel.GridExternalName; | ||
687 | hgt.Data["ServiceToken"] = travel.ServiceToken; | ||
688 | hgt.Data["ClientIPAddress"] = travel.ClientIPAddress; | ||
689 | hgt.Data["MyIPAddress"] = travel.MyIpAddress; | ||
690 | |||
691 | m_Database.Store(hgt); | ||
692 | } | ||
690 | #endregion | 693 | #endregion |
691 | 694 | ||
692 | } | 695 | } |
693 | 696 | ||
694 | class TravelingAgentInfo | 697 | class TravelingAgentInfo |
695 | { | 698 | { |
699 | public UUID SessionID; | ||
696 | public UUID UserID; | 700 | public UUID UserID; |
697 | public string GridExternalName = string.Empty; | 701 | public string GridExternalName = string.Empty; |
698 | public string ServiceToken = string.Empty; | 702 | public string ServiceToken = string.Empty; |
699 | public string ClientIPAddress = string.Empty; // as seen from this user agent service | 703 | public string ClientIPAddress = string.Empty; // as seen from this user agent service |
700 | public string MyIpAddress = string.Empty; // the user agent service's external IP, as seen from the next gatekeeper | 704 | public string MyIpAddress = string.Empty; // the user agent service's external IP, as seen from the next gatekeeper |
705 | |||
706 | public TravelingAgentInfo(HGTravelingData t) | ||
707 | { | ||
708 | if (t.Data != null) | ||
709 | { | ||
710 | SessionID = new UUID(t.SessionID); | ||
711 | UserID = new UUID(t.UserID); | ||
712 | GridExternalName = t.Data["GridExternalName"]; | ||
713 | ServiceToken = t.Data["ServiceToken"]; | ||
714 | ClientIPAddress = t.Data["ClientIPAddress"]; | ||
715 | MyIpAddress = t.Data["MyIPAddress"]; | ||
716 | } | ||
717 | } | ||
718 | |||
719 | public TravelingAgentInfo(TravelingAgentInfo old) | ||
720 | { | ||
721 | if (old != null) | ||
722 | { | ||
723 | SessionID = old.SessionID; | ||
724 | UserID = old.UserID; | ||
725 | GridExternalName = old.GridExternalName; | ||
726 | ServiceToken = old.ServiceToken; | ||
727 | ClientIPAddress = old.ClientIPAddress; | ||
728 | MyIpAddress = old.MyIpAddress; | ||
729 | } | ||
730 | } | ||
701 | } | 731 | } |
702 | 732 | ||
703 | } | 733 | } |