UserAgentService: change handling of its external IP

0.9.1.0-post-fixes
UbitUmarov 2019-04-06 16:09:42 +01:00
parent 0ebb1f3f4b
commit b7c1d6e7f5
2 changed files with 28 additions and 31 deletions

View File

@ -99,15 +99,8 @@ namespace OpenSim.Services.Connectors.Simulation
}
public bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint flags, EntityTransferContext ctx, out string reason)
{
string tmp = String.Empty;
return CreateAgent(source, destination, aCircuit, flags, ctx, out tmp, out reason);
}
public bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint flags, EntityTransferContext ctx, out string myipaddress, out string reason)
{
reason = String.Empty;
myipaddress = String.Empty;
if (destination == null)
{
@ -134,7 +127,6 @@ namespace OpenSim.Services.Connectors.Simulation
reason = data["reason"].AsString();
success = data["success"].AsBoolean();
myipaddress = data["your_ip"].AsString();
return success;
}
@ -149,7 +141,6 @@ namespace OpenSim.Services.Connectors.Simulation
reason = data["reason"].AsString();
success = data["success"].AsBoolean();
myipaddress = data["your_ip"].AsString();
m_log.WarnFormat(
"[REMOTE SIMULATION CONNECTOR]: Remote simulator {0} did not accept compressed transfer, suggest updating it.", destination.RegionName);
return success;

View File

@ -73,6 +73,7 @@ namespace OpenSim.Services.HypergridService
protected static FriendsSimConnector m_FriendsSimConnector; // grid
protected static string m_GridName;
protected static string m_MyExternalIP = "";
protected static int m_LevelOutsideContacts;
protected static bool m_ShowDetails;
@ -147,9 +148,20 @@ namespace OpenSim.Services.HypergridService
}
}
if (!m_GridName.EndsWith("/"))
m_GridName = m_GridName + "/";
if (!string.IsNullOrEmpty(m_GridName))
{
m_GridName = m_GridName.ToLowerInvariant();
if (!m_GridName.EndsWith("/"))
m_GridName = m_GridName + "/";
Uri gateURI;
if(!Uri.TryCreate(m_GridName, UriKind.Absolute, out gateURI))
throw new Exception(String.Format("[UserAgentService] could not parse gatekeeper uri"));
string host = gateURI.DnsSafeHost;
IPAddress ip = Util.GetHostFromDNS(host);
if(ip == null)
throw new Exception(String.Format("[UserAgentService] failed to resolve gatekeeper host"));
m_MyExternalIP = ip.ToString();
}
// Finally some cleanup
m_Database.DeleteOld();
@ -189,7 +201,6 @@ namespace OpenSim.Services.HypergridService
}
}
public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt)
{
position = new Vector3(128, 128, 0); lookAt = Vector3.UnitY;
@ -222,7 +233,7 @@ namespace OpenSim.Services.HypergridService
m_log.DebugFormat("[USER AGENT SERVICE]: Request to login user {0} {1} (@{2}) to grid {3}",
agentCircuit.firstname, agentCircuit.lastname, (fromLogin ? agentCircuit.IPAddress : "stored IP"), gatekeeper.ServerURI);
string gridName = gatekeeper.ServerURI;
string gridName = gatekeeper.ServerURI.ToLowerInvariant();
UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, agentCircuit.AgentID);
if (account == null)
@ -269,8 +280,13 @@ namespace OpenSim.Services.HypergridService
TravelingAgentInfo old = null;
TravelingAgentInfo travel = CreateTravelInfo(agentCircuit, region, fromLogin, out old);
if(!fromLogin && old != null && !string.IsNullOrEmpty(old.ClientIPAddress))
{
m_log.DebugFormat("[USER AGENT SERVICE]: stored IP = {0}. Old circuit IP: {1}", old.ClientIPAddress, agentCircuit.IPAddress);
agentCircuit.IPAddress = old.ClientIPAddress;
}
bool success = false;
string myExternalIP = string.Empty;
m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}, desired region: {2}", m_GridName, gridName, region.RegionID);
@ -282,7 +298,7 @@ namespace OpenSim.Services.HypergridService
{
//TODO: Should there not be a call to QueryAccess here?
EntityTransferContext ctx = new EntityTransferContext();
success = m_GatekeeperConnector.CreateAgent(source, region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, ctx, out myExternalIP, out reason);
success = m_GatekeeperConnector.CreateAgent(source, region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, ctx, out reason);
}
if (!success)
@ -300,14 +316,6 @@ namespace OpenSim.Services.HypergridService
// Everything is ok
if (!fromLogin)
{
// Update the perceived IP Address of our grid
m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP);
}
travel.MyIpAddress = myExternalIP;
StoreTravelInfo(travel);
return true;
@ -384,10 +392,12 @@ namespace OpenSim.Services.HypergridService
TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
bool result = travel.ClientIPAddress == reportedIP || travel.MyIpAddress == reportedIP; // NATed
bool result = travel.ClientIPAddress == reportedIP;
if(!result && !string.IsNullOrEmpty(m_MyExternalIP))
result = reportedIP == m_MyExternalIP; // 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);
m_log.DebugFormat("[USER AGENT SERVICE]: Comparing {0} with login IP {1} and MyIP {2}; result is {3}",
reportedIP, travel.ClientIPAddress, m_MyExternalIP, result);
return result;
}
@ -704,7 +714,6 @@ namespace OpenSim.Services.HypergridService
hgt.Data["GridExternalName"] = travel.GridExternalName;
hgt.Data["ServiceToken"] = travel.ServiceToken;
hgt.Data["ClientIPAddress"] = travel.ClientIPAddress;
hgt.Data["MyIPAddress"] = travel.MyIpAddress;
m_Database.Store(hgt);
}
@ -719,7 +728,6 @@ namespace OpenSim.Services.HypergridService
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)
{
@ -730,7 +738,6 @@ namespace OpenSim.Services.HypergridService
GridExternalName = t.Data["GridExternalName"];
ServiceToken = t.Data["ServiceToken"];
ClientIPAddress = t.Data["ClientIPAddress"];
MyIpAddress = t.Data["MyIPAddress"];
}
}
@ -743,7 +750,6 @@ namespace OpenSim.Services.HypergridService
GridExternalName = old.GridExternalName;
ServiceToken = old.ServiceToken;
ClientIPAddress = old.ClientIPAddress;
MyIpAddress = old.MyIpAddress;
}
}
}