some cleanup and assume Linux/mono DNS is just broken...

0.9.0-post-fixes
UbitUmarov 2017-05-29 05:22:21 +01:00
parent 7be6e16555
commit 8f86de265c
3 changed files with 57 additions and 45 deletions

View File

@ -1009,6 +1009,9 @@ namespace OpenSim.Framework
public static IPAddress GetHostFromDNS(string dnsAddress) public static IPAddress GetHostFromDNS(string dnsAddress)
{ {
// If it is already an IP, avoid possible broken mono from seeing it // If it is already an IP, avoid possible broken mono from seeing it
if(String.IsNullOrWhiteSpace(dnsAddress))
return null;
IPAddress ia = null; IPAddress ia = null;
if (IPAddress.TryParse(dnsAddress, out ia) && ia != null) if (IPAddress.TryParse(dnsAddress, out ia) && ia != null)
{ {
@ -1016,31 +1019,31 @@ namespace OpenSim.Framework
return null; return null;
return ia; return ia;
} }
// Reset for next check
ia = null; IPHostEntry IPH;
try try
{ {
foreach (IPAddress Adr in Dns.GetHostAddresses(dnsAddress)) IPH = Dns.GetHostEntry(dnsAddress);
{
if (ia == null)
ia = Adr;
if (Adr.AddressFamily == AddressFamily.InterNetwork)
{
ia = Adr;
break;
}
}
} }
catch // (SocketException e) catch // (SocketException e)
{ {
/*throw new Exception( return null;
"Unable to resolve local hostname " + m_externalHostName + " innerException of type '" + }
e + "' attached to this exception", e);*/
// Don't throw a fatal exception here, instead, return Null and handle it in the caller. if(IPH == null || IPH.AddressList.Length == 0)
// Reason is, on systems such as OSgrid it has occured that known hostnames stop
// resolving and thus make surrounding regions crash out with this exception.
return null; return null;
ia = null;
foreach (IPAddress Adr in IPH.AddressList)
{
if (ia == null)
ia = Adr;
if (Adr.AddressFamily == AddressFamily.InterNetwork)
{
ia = Adr;
break;
}
} }
return ia; return ia;
} }
@ -1075,26 +1078,31 @@ namespace OpenSim.Framework
return null; return null;
return getEndPoint(ia, port); return getEndPoint(ia, port);
} }
// Reset for next check IPHostEntry IPH;
ia = null;
try try
{ {
foreach (IPAddress Adr in Dns.GetHostAddresses(hostname)) IPH = Dns.GetHostEntry(hostname);
{
if (ia == null)
ia = Adr;
if (Adr.AddressFamily == AddressFamily.InterNetwork)
{
ia = Adr;
break;
}
}
} }
catch // (SocketException e) catch // (SocketException e)
{ {
ia = null; return null;
}
if(IPH == null || IPH.AddressList.Length == 0)
return null;
ia = null;
foreach (IPAddress Adr in IPH.AddressList)
{
if (ia == null)
ia = Adr;
if (Adr.AddressFamily == AddressFamily.InterNetwork)
{
ia = Adr;
break;
}
} }
return getEndPoint(ia,port); return getEndPoint(ia,port);

View File

@ -157,7 +157,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
m_idCache = new ExpiringCache<ulong, DateTime>(); m_idCache = new ExpiringCache<ulong, DateTime>();
m_bannedRegions.Add(pAgentID, m_idCache, TimeSpan.FromSeconds(newTime)); m_bannedRegions.Add(pAgentID, m_idCache, TimeSpan.FromSeconds(newTime));
} }
m_idCache.Add(pRegionHandle, DateTime.UtcNow + TimeSpan.FromSeconds(extendTime), TimeSpan.FromSeconds(extendTime)); m_idCache.Add(pRegionHandle, DateTime.UtcNow + TimeSpan.FromSeconds(extendTime), extendTime);
} }
// Remove the agent from the region's banned list // Remove the agent from the region's banned list
@ -1488,13 +1488,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
Math.Max(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY)); Math.Max(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY));
if (neighbourRegion == null) if (neighbourRegion == null)
{
failureReason = "no region found"; // debug -> to remove
return null; return null;
}
if (m_bannedRegionCache.IfBanned(neighbourRegion.RegionHandle, agentID)) if (m_bannedRegionCache.IfBanned(neighbourRegion.RegionHandle, agentID))
{ {
failureReason = "Access Denied"; failureReason = "Access Denied or Temporary not possible";
return null; return null;
} }
@ -1506,14 +1504,15 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
pos.Z); pos.Z);
string homeURI = scene.GetAgentHomeURI(agentID); string homeURI = scene.GetAgentHomeURI(agentID);
if (!scene.SimulationService.QueryAccess( if (!scene.SimulationService.QueryAccess(
neighbourRegion, agentID, homeURI, false, newpos, neighbourRegion, agentID, homeURI, false, newpos,
scene.GetFormatsOffered(), ctx, out failureReason)) scene.GetFormatsOffered(), ctx, out failureReason))
{ {
// remember the fail // remember the fail
m_bannedRegionCache.Add(neighbourRegion.RegionHandle, agentID); m_bannedRegionCache.Add(neighbourRegion.RegionHandle, agentID);
failureReason = "Access Denied"; if(String.IsNullOrWhiteSpace(failureReason))
failureReason = "Access Denied";
return null; return null;
} }
@ -2171,7 +2170,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
InformClientOfNeighbourAsync(sp, cagents[count], neighbour, ipe, true); InformClientOfNeighbourAsync(sp, cagents[count], neighbour, ipe, true);
else else
{ {
m_log.DebugFormat("[ENTITY TRANSFER MODULE]: DNS for neighbour {0} lost", neighbour.ExternalHostName); m_log.DebugFormat("[ENTITY TRANSFER MODULE]: lost DNS resolution for neighbour {0}", neighbour.ExternalHostName);
} }
count++; count++;
} }

View File

@ -70,9 +70,14 @@ namespace OpenSim.Services.Connectors.Hypergrid
{ {
Uri m_Uri = new Uri(m_ServerURL); Uri m_Uri = new Uri(m_ServerURL);
IPAddress ip = Util.GetHostFromDNS(m_Uri.Host); IPAddress ip = Util.GetHostFromDNS(m_Uri.Host);
m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString()); if(ip != null)
if (!m_ServerURL.EndsWith("/")) {
m_ServerURL += "/"; m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString());
if (!m_ServerURL.EndsWith("/"))
m_ServerURL += "/";
}
else
m_log.DebugFormat("[USER AGENT CONNECTOR]: Failed to resolv address of {0}", url);
} }
catch (Exception e) catch (Exception e)
{ {