mirror of
https://github.com/opensim/opensim.git
synced 2026-08-09 02:36:00 +08:00
Merge branch 'master' into careminster
Conflicts: OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs OpenSim/Region/Framework/Scenes/Scene.cs OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs OpenSim/Region/Framework/Scenes/SceneObjectPart.cs OpenSim/Region/Framework/Scenes/ScenePresence.cs OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs OpenSim/Server/Handlers/Simulation/AgentHandlers.cs OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs OpenSim/Services/HypergridService/UserAgentService.cs
This commit is contained in:
@@ -419,6 +419,12 @@ namespace OpenSim.Services.HypergridService
|
||||
if (!CheckAddress(aCircuit.ServiceSessionID))
|
||||
return false;
|
||||
|
||||
if (string.IsNullOrEmpty(aCircuit.IPAddress))
|
||||
{
|
||||
m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide a client IP address.");
|
||||
return false;
|
||||
}
|
||||
|
||||
string userURL = string.Empty;
|
||||
if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
|
||||
userURL = aCircuit.ServiceURLs["HomeURI"].ToString();
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenSim.Services.HypergridService
|
||||
LogManager.GetLogger(
|
||||
MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private string m_HomeURL;
|
||||
// private string m_HomeURL;
|
||||
private IUserAccountService m_UserAccountService;
|
||||
private IAvatarService m_AvatarService;
|
||||
|
||||
@@ -96,8 +96,8 @@ namespace OpenSim.Services.HypergridService
|
||||
if (m_AvatarService == null)
|
||||
throw new Exception(String.Format("Unable to create m_AvatarService from {0}", avatarDll));
|
||||
|
||||
m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
|
||||
new string[] { "Startup", "Hypergrid", m_ConfigName }, String.Empty);
|
||||
// m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
|
||||
// new string[] { "Startup", "Hypergrid", m_ConfigName }, String.Empty);
|
||||
|
||||
// m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
|
||||
using OpenSim.Data;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Services.Connectors.Friends;
|
||||
using OpenSim.Services.Connectors.Hypergrid;
|
||||
@@ -50,14 +51,14 @@ namespace OpenSim.Services.HypergridService
|
||||
/// needs to do it for them.
|
||||
/// Once we have better clients, this shouldn't be needed.
|
||||
/// </summary>
|
||||
public class UserAgentService : IUserAgentService
|
||||
public class UserAgentService : UserAgentServiceBase, IUserAgentService
|
||||
{
|
||||
private static readonly ILog m_log =
|
||||
LogManager.GetLogger(
|
||||
MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
// This will need to go into a DB table
|
||||
static Dictionary<UUID, TravelingAgentInfo> m_TravelingAgents = new Dictionary<UUID, TravelingAgentInfo>();
|
||||
//static Dictionary<UUID, TravelingAgentInfo> m_Database = new Dictionary<UUID, TravelingAgentInfo>();
|
||||
|
||||
static bool m_Initialized = false;
|
||||
|
||||
@@ -86,6 +87,7 @@ namespace OpenSim.Services.HypergridService
|
||||
}
|
||||
|
||||
public UserAgentService(IConfigSource config, IFriendsSimConnector friendsConnector)
|
||||
: base(config)
|
||||
{
|
||||
// Let's set this always, because we don't know the sequence
|
||||
// of instantiations
|
||||
@@ -146,6 +148,9 @@ namespace OpenSim.Services.HypergridService
|
||||
if (!m_GridName.EndsWith("/"))
|
||||
m_GridName = m_GridName + "/";
|
||||
|
||||
// Finally some cleanup
|
||||
m_Database.DeleteOld();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +265,8 @@ namespace OpenSim.Services.HypergridService
|
||||
|
||||
// Generate a new service session
|
||||
agentCircuit.ServiceSessionID = region.ServerURI + ";" + UUID.Random();
|
||||
TravelingAgentInfo old = UpdateTravelInfo(agentCircuit, region);
|
||||
TravelingAgentInfo old = null;
|
||||
TravelingAgentInfo travel = CreateTravelInfo(agentCircuit, region, fromLogin, out old);
|
||||
|
||||
bool success = false;
|
||||
string myExternalIP = string.Empty;
|
||||
@@ -282,23 +288,21 @@ namespace OpenSim.Services.HypergridService
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}",
|
||||
agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason);
|
||||
|
||||
// restore the old travel info
|
||||
lock (m_TravelingAgents)
|
||||
{
|
||||
if (old == null)
|
||||
m_TravelingAgents.Remove(agentCircuit.SessionID);
|
||||
else
|
||||
m_TravelingAgents[agentCircuit.SessionID] = old;
|
||||
}
|
||||
if (old != null)
|
||||
StoreTravelInfo(old);
|
||||
else
|
||||
m_Database.Delete(agentCircuit.SessionID);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Everything is ok
|
||||
|
||||
// Update the perceived IP Address of our grid
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP);
|
||||
// else set the IP addresses associated with this client
|
||||
if (fromLogin)
|
||||
m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = agentCircuit.IPAddress;
|
||||
m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP;
|
||||
travel.MyIpAddress = myExternalIP;
|
||||
|
||||
StoreTravelInfo(travel);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -309,57 +313,39 @@ namespace OpenSim.Services.HypergridService
|
||||
return LoginAgentToGrid(agentCircuit, gatekeeper, finalDestination, false, out reason);
|
||||
}
|
||||
|
||||
private void SetClientIP(UUID sessionID, string ip)
|
||||
TravelingAgentInfo CreateTravelInfo(AgentCircuitData agentCircuit, GridRegion region, bool fromLogin, out TravelingAgentInfo existing)
|
||||
{
|
||||
if (m_TravelingAgents.ContainsKey(sessionID))
|
||||
HGTravelingData hgt = m_Database.Get(agentCircuit.SessionID);
|
||||
existing = null;
|
||||
|
||||
if (hgt != null)
|
||||
{
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: Setting IP {0} for session {1}", ip, sessionID);
|
||||
m_TravelingAgents[sessionID].ClientIPAddress = ip;
|
||||
// Very important! Override whatever this agent comes with.
|
||||
// UserAgentService always sets the IP for every new agent
|
||||
// with the original IP address.
|
||||
existing = new TravelingAgentInfo(hgt);
|
||||
agentCircuit.IPAddress = existing.ClientIPAddress;
|
||||
}
|
||||
}
|
||||
|
||||
TravelingAgentInfo UpdateTravelInfo(AgentCircuitData agentCircuit, GridRegion region)
|
||||
{
|
||||
TravelingAgentInfo travel = new TravelingAgentInfo();
|
||||
TravelingAgentInfo old = null;
|
||||
lock (m_TravelingAgents)
|
||||
{
|
||||
if (m_TravelingAgents.ContainsKey(agentCircuit.SessionID))
|
||||
{
|
||||
// Very important! Override whatever this agent comes with.
|
||||
// UserAgentService always sets the IP for every new agent
|
||||
// with the original IP address.
|
||||
agentCircuit.IPAddress = m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress;
|
||||
|
||||
old = m_TravelingAgents[agentCircuit.SessionID];
|
||||
}
|
||||
|
||||
m_TravelingAgents[agentCircuit.SessionID] = travel;
|
||||
}
|
||||
TravelingAgentInfo travel = new TravelingAgentInfo(existing);
|
||||
travel.SessionID = agentCircuit.SessionID;
|
||||
travel.UserID = agentCircuit.AgentID;
|
||||
travel.GridExternalName = region.ServerURI;
|
||||
travel.ServiceToken = agentCircuit.ServiceSessionID;
|
||||
if (old != null)
|
||||
travel.ClientIPAddress = old.ClientIPAddress;
|
||||
|
||||
return old;
|
||||
if (fromLogin)
|
||||
travel.ClientIPAddress = agentCircuit.IPAddress;
|
||||
|
||||
StoreTravelInfo(travel);
|
||||
|
||||
return travel;
|
||||
}
|
||||
|
||||
public void LogoutAgent(UUID userID, UUID sessionID)
|
||||
{
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: User {0} logged out", userID);
|
||||
|
||||
lock (m_TravelingAgents)
|
||||
{
|
||||
List<UUID> travels = new List<UUID>();
|
||||
foreach (KeyValuePair<UUID, TravelingAgentInfo> kvp in m_TravelingAgents)
|
||||
if (kvp.Value == null) // do some clean up
|
||||
travels.Add(kvp.Key);
|
||||
else if (kvp.Value.UserID == userID)
|
||||
travels.Add(kvp.Key);
|
||||
foreach (UUID session in travels)
|
||||
m_TravelingAgents.Remove(session);
|
||||
}
|
||||
m_Database.Delete(sessionID);
|
||||
|
||||
GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(userID.ToString());
|
||||
if (guinfo != null)
|
||||
@@ -369,10 +355,11 @@ namespace OpenSim.Services.HypergridService
|
||||
// We need to prevent foreign users with the same UUID as a local user
|
||||
public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName)
|
||||
{
|
||||
if (!m_TravelingAgents.ContainsKey(sessionID))
|
||||
HGTravelingData hgt = m_Database.Get(sessionID);
|
||||
if (hgt == null)
|
||||
return false;
|
||||
|
||||
TravelingAgentInfo travel = m_TravelingAgents[sessionID];
|
||||
TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
|
||||
|
||||
return travel.GridExternalName.ToLower() == thisGridExternalName.ToLower();
|
||||
}
|
||||
@@ -385,29 +372,32 @@ namespace OpenSim.Services.HypergridService
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: Verifying Client session {0} with reported IP {1}.",
|
||||
sessionID, reportedIP);
|
||||
|
||||
if (m_TravelingAgents.ContainsKey(sessionID))
|
||||
{
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: Comparing with login IP {0} and MyIP {1}",
|
||||
m_TravelingAgents[sessionID].ClientIPAddress, m_TravelingAgents[sessionID].MyIpAddress);
|
||||
HGTravelingData hgt = m_Database.Get(sessionID);
|
||||
if (hgt == null)
|
||||
return false;
|
||||
|
||||
return m_TravelingAgents[sessionID].ClientIPAddress == reportedIP ||
|
||||
m_TravelingAgents[sessionID].MyIpAddress == reportedIP; // NATed
|
||||
}
|
||||
TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
|
||||
|
||||
return false;
|
||||
bool result = travel.ClientIPAddress == reportedIP || travel.MyIpAddress == reportedIP; // NATed
|
||||
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: Comparing {0} with login IP {1} and MyIP {1}; result is {3}",
|
||||
reportedIP, travel.ClientIPAddress, travel.MyIpAddress, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool VerifyAgent(UUID sessionID, string token)
|
||||
{
|
||||
if (m_TravelingAgents.ContainsKey(sessionID))
|
||||
HGTravelingData hgt = m_Database.Get(sessionID);
|
||||
if (hgt == null)
|
||||
{
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, m_TravelingAgents[sessionID].ServiceToken);
|
||||
return m_TravelingAgents[sessionID].ServiceToken == token;
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID);
|
||||
|
||||
return false;
|
||||
TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
|
||||
m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, travel.ServiceToken);
|
||||
return travel.ServiceToken == token;
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
@@ -470,17 +460,17 @@ namespace OpenSim.Services.HypergridService
|
||||
}
|
||||
}
|
||||
|
||||
// Lastly, let's notify the rest who may be online somewhere else
|
||||
foreach (string user in usersToBeNotified)
|
||||
{
|
||||
UUID id = new UUID(user);
|
||||
if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName)
|
||||
{
|
||||
string url = m_TravelingAgents[id].GridExternalName;
|
||||
// forward
|
||||
m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url);
|
||||
}
|
||||
}
|
||||
//// Lastly, let's notify the rest who may be online somewhere else
|
||||
//foreach (string user in usersToBeNotified)
|
||||
//{
|
||||
// UUID id = new UUID(user);
|
||||
// if (m_Database.ContainsKey(id) && m_Database[id].GridExternalName != m_GridName)
|
||||
// {
|
||||
// string url = m_Database[id].GridExternalName;
|
||||
// // forward
|
||||
// m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url);
|
||||
// }
|
||||
//}
|
||||
|
||||
// and finally, let's send the online friends
|
||||
if (online)
|
||||
@@ -607,16 +597,13 @@ namespace OpenSim.Services.HypergridService
|
||||
|
||||
public string LocateUser(UUID userID)
|
||||
{
|
||||
foreach (TravelingAgentInfo t in m_TravelingAgents.Values)
|
||||
{
|
||||
if (t == null)
|
||||
{
|
||||
m_log.ErrorFormat("[USER AGENT SERVICE]: Oops! Null TravelingAgentInfo. Please report this on mantis");
|
||||
continue;
|
||||
}
|
||||
if (t.UserID == userID && !m_GridName.Equals(t.GridExternalName))
|
||||
return t.GridExternalName;
|
||||
}
|
||||
HGTravelingData[] hgts = m_Database.GetSessions(userID);
|
||||
if (hgts == null)
|
||||
return string.Empty;
|
||||
|
||||
foreach (HGTravelingData t in hgts)
|
||||
if (t.Data.ContainsKey("GridExternalName") && !m_GridName.Equals(t.Data["GridExternalName"]))
|
||||
return t.Data["GridExternalName"];
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
@@ -687,17 +674,60 @@ namespace OpenSim.Services.HypergridService
|
||||
return exception;
|
||||
}
|
||||
|
||||
private void StoreTravelInfo(TravelingAgentInfo travel)
|
||||
{
|
||||
if (travel == null)
|
||||
return;
|
||||
|
||||
HGTravelingData hgt = new HGTravelingData();
|
||||
hgt.SessionID = travel.SessionID;
|
||||
hgt.UserID = travel.UserID;
|
||||
hgt.Data = new Dictionary<string, string>();
|
||||
hgt.Data["GridExternalName"] = travel.GridExternalName;
|
||||
hgt.Data["ServiceToken"] = travel.ServiceToken;
|
||||
hgt.Data["ClientIPAddress"] = travel.ClientIPAddress;
|
||||
hgt.Data["MyIPAddress"] = travel.MyIpAddress;
|
||||
|
||||
m_Database.Store(hgt);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
class TravelingAgentInfo
|
||||
{
|
||||
public UUID SessionID;
|
||||
public UUID UserID;
|
||||
public string GridExternalName = string.Empty;
|
||||
public string ServiceToken = string.Empty;
|
||||
public string ClientIPAddress = string.Empty; // as seen from this user agent service
|
||||
public string MyIpAddress = string.Empty; // the user agent service's external IP, as seen from the next gatekeeper
|
||||
|
||||
public TravelingAgentInfo(HGTravelingData t)
|
||||
{
|
||||
if (t.Data != null)
|
||||
{
|
||||
SessionID = new UUID(t.SessionID);
|
||||
UserID = new UUID(t.UserID);
|
||||
GridExternalName = t.Data["GridExternalName"];
|
||||
ServiceToken = t.Data["ServiceToken"];
|
||||
ClientIPAddress = t.Data["ClientIPAddress"];
|
||||
MyIpAddress = t.Data["MyIPAddress"];
|
||||
}
|
||||
}
|
||||
|
||||
public TravelingAgentInfo(TravelingAgentInfo old)
|
||||
{
|
||||
if (old != null)
|
||||
{
|
||||
SessionID = old.SessionID;
|
||||
UserID = old.UserID;
|
||||
GridExternalName = old.GridExternalName;
|
||||
ServiceToken = old.ServiceToken;
|
||||
ClientIPAddress = old.ClientIPAddress;
|
||||
MyIpAddress = old.MyIpAddress;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
84
OpenSim/Services/HypergridService/UserAgentServiceBase.cs
Normal file
84
OpenSim/Services/HypergridService/UserAgentServiceBase.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSimulator Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Data;
|
||||
using OpenSim.Services.Interfaces;
|
||||
using OpenSim.Services.Base;
|
||||
|
||||
namespace OpenSim.Services.HypergridService
|
||||
{
|
||||
public class UserAgentServiceBase : ServiceBase
|
||||
{
|
||||
protected IHGTravelingData m_Database = null;
|
||||
|
||||
public UserAgentServiceBase(IConfigSource config)
|
||||
: base(config)
|
||||
{
|
||||
string dllName = String.Empty;
|
||||
string connString = String.Empty;
|
||||
string realm = "hg_traveling_data";
|
||||
|
||||
//
|
||||
// Try reading the [DatabaseService] section, if it exists
|
||||
//
|
||||
IConfig dbConfig = config.Configs["DatabaseService"];
|
||||
if (dbConfig != null)
|
||||
{
|
||||
if (dllName == String.Empty)
|
||||
dllName = dbConfig.GetString("StorageProvider", String.Empty);
|
||||
if (connString == String.Empty)
|
||||
connString = dbConfig.GetString("ConnectionString", String.Empty);
|
||||
}
|
||||
|
||||
//
|
||||
// [UserAgentService] section overrides [DatabaseService], if it exists
|
||||
//
|
||||
IConfig gridConfig = config.Configs["UserAgentService"];
|
||||
if (gridConfig != null)
|
||||
{
|
||||
dllName = gridConfig.GetString("StorageProvider", dllName);
|
||||
connString = gridConfig.GetString("ConnectionString", connString);
|
||||
realm = gridConfig.GetString("Realm", realm);
|
||||
}
|
||||
|
||||
//
|
||||
// We tried, but this doesn't exist. We can't proceed.
|
||||
//
|
||||
if (dllName.Equals(String.Empty))
|
||||
throw new Exception("No StorageProvider configured");
|
||||
|
||||
m_Database = LoadPlugin<IHGTravelingData>(dllName, new Object[] { connString, realm });
|
||||
if (m_Database == null)
|
||||
throw new Exception("Could not find a storage interface in the given module");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user