* Fixes [irritating] edge case in Util.GetLocalHost which could return an IPv6 address if no non-loopback IPv4 address can be found.

* Restores internal IPv6 support to NetworkUtil.*
* Fixes bad login unit tests.
0.6.6-post-fixes
Adam Frisby 2009-05-23 07:51:29 +00:00
parent 6fe55a7ff8
commit 70f6a2852e
3 changed files with 47 additions and 15 deletions

View File

@ -103,7 +103,10 @@ namespace OpenSim.Framework.Communications.Tests
XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
XmlRpcResponse response = loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); IPAddress tmpLocal = Util.GetLocalHost();
IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
Hashtable responseData = (Hashtable)response.Value; Hashtable responseData = (Hashtable)response.Value;
Assert.That(responseData["first_name"], Is.EqualTo(m_firstName)); Assert.That(responseData["first_name"], Is.EqualTo(m_firstName));
@ -113,7 +116,7 @@ namespace OpenSim.Framework.Communications.Tests
Regex capsSeedPattern Regex capsSeedPattern
= new Regex("^http://" = new Regex("^http://"
+ m_regionExternalName + NetworkUtil.GetHostFor(tmpLocal, m_regionExternalName)
+ ":9000/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}0000/$"); + ":9000/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}0000/$");
Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True); Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True);
@ -140,7 +143,10 @@ namespace OpenSim.Framework.Communications.Tests
XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); IPAddress tmpLocal = Util.GetLocalHost();
IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
Hashtable responseData = (Hashtable)response.Value; Hashtable responseData = (Hashtable)response.Value;
UserAgentData uagent = m_userProfileData.CurrentAgent; UserAgentData uagent = m_userProfileData.CurrentAgent;
@ -163,7 +169,7 @@ namespace OpenSim.Framework.Communications.Tests
Regex capsSeedPattern Regex capsSeedPattern
= new Regex("^http://" = new Regex("^http://"
+ m_regionExternalName + NetworkUtil.GetHostFor(tmpLocal, m_regionExternalName)
+ ":9000/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}0000/$"); + ":9000/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}0000/$");
Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True); Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True);
@ -194,14 +200,16 @@ namespace OpenSim.Framework.Communications.Tests
XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); IPAddress tmpLocal = Util.GetLocalHost();
IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
Hashtable responseData = (Hashtable)response.Value; Hashtable responseData = (Hashtable)response.Value;
ArrayList friendslist = (ArrayList) responseData["buddy-list"]; ArrayList friendslist = (ArrayList) responseData["buddy-list"];
Assert.That(friendslist,Is.Not.Null); Assert.That(friendslist,Is.Not.Null);
Hashtable buddy1 = (Hashtable) friendslist[0]; Hashtable buddy1 = (Hashtable) friendslist[0];
Hashtable buddy2 = (Hashtable) friendslist[1]; Hashtable buddy2 = (Hashtable) friendslist[1];
Assert.That(friendslist.Count, Is.EqualTo(2)); Assert.That(friendslist.Count, Is.EqualTo(2));
@ -231,7 +239,10 @@ namespace OpenSim.Framework.Communications.Tests
XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); IPAddress tmpLocal = Util.GetLocalHost();
IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
Hashtable responseData = (Hashtable)response.Value; Hashtable responseData = (Hashtable)response.Value;
Assert.That(responseData["message"], Is.EqualTo(error_auth_message)); Assert.That(responseData["message"], Is.EqualTo(error_auth_message));
@ -256,7 +267,10 @@ namespace OpenSim.Framework.Communications.Tests
XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); IPAddress tmpLocal = Util.GetLocalHost();
IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
Hashtable responseData = (Hashtable)response.Value; Hashtable responseData = (Hashtable)response.Value;
Assert.That(responseData["message"], Is.EqualTo(error_auth_message)); Assert.That(responseData["message"], Is.EqualTo(error_auth_message));
@ -281,7 +295,10 @@ namespace OpenSim.Framework.Communications.Tests
XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); IPAddress tmpLocal = Util.GetLocalHost();
IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
Hashtable responseData = (Hashtable)response.Value; Hashtable responseData = (Hashtable)response.Value;
Assert.That(responseData["message"], Is.EqualTo(error_xml_message)); Assert.That(responseData["message"], Is.EqualTo(error_xml_message));
@ -312,20 +329,24 @@ namespace OpenSim.Framework.Communications.Tests
// First we log in. // First we log in.
XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80));
IPAddress tmpLocal = Util.GetLocalHost();
IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
Hashtable responseData = (Hashtable)response.Value; Hashtable responseData = (Hashtable)response.Value;
Assert.That(responseData["message"], Is.EqualTo("Hello folks")); Assert.That(responseData["message"], Is.EqualTo("Hello folks"));
// Then we try again, this time expecting failure. // Then we try again, this time expecting failure.
request = new XmlRpcRequest("login_to_simulator", sendParams); request = new XmlRpcRequest("login_to_simulator", sendParams);
response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
responseData = (Hashtable)response.Value; responseData = (Hashtable)response.Value;
Assert.That(responseData["message"], Is.EqualTo(error_already_logged)); Assert.That(responseData["message"], Is.EqualTo(error_already_logged));
// Finally the third time we should be able to get right back in. // Finally the third time we should be able to get right back in.
request = new XmlRpcRequest("login_to_simulator", sendParams); request = new XmlRpcRequest("login_to_simulator", sendParams);
response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
responseData = (Hashtable)response.Value; responseData = (Hashtable)response.Value;
Assert.That(responseData["message"], Is.EqualTo("Hello folks")); Assert.That(responseData["message"], Is.EqualTo("Hello folks"));

View File

@ -73,9 +73,8 @@ namespace OpenSim.Framework
private static IPAddress GetExternalIPFor(IPAddress destination, string defaultHostname) private static IPAddress GetExternalIPFor(IPAddress destination, string defaultHostname)
{ {
bool ipv6 = false;
// Adds IPv6 Support (Not that any of the major protocols supports it...) // Adds IPv6 Support (Not that any of the major protocols supports it...)
if (ipv6 && destination.AddressFamily == AddressFamily.InterNetworkV6) if (destination.AddressFamily == AddressFamily.InterNetworkV6)
{ {
foreach (IPAddress host in Dns.GetHostAddresses(defaultHostname)) foreach (IPAddress host in Dns.GetHostAddresses(defaultHostname))
{ {
@ -91,11 +90,15 @@ namespace OpenSim.Framework
return null; return null;
// Check if we're accessing localhost. // Check if we're accessing localhost.
foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName())) foreach (KeyValuePair<IPAddress, IPAddress> pair in m_subnets)
{ {
IPAddress host = pair.Value;
if (host.Equals(destination) && host.AddressFamily == AddressFamily.InterNetwork) if (host.Equals(destination) && host.AddressFamily == AddressFamily.InterNetwork)
{
m_log.Info("[NATROUTING] Localhost user detected, sending them '" + host + "' instead of '" + defaultHostname + "'");
return destination; return destination;
} }
}
// Check for same LAN segment // Check for same LAN segment
foreach (KeyValuePair<IPAddress, IPAddress> subnet in m_subnets) foreach (KeyValuePair<IPAddress, IPAddress> subnet in m_subnets)

View File

@ -546,7 +546,15 @@ namespace OpenSim.Framework
} }
if (hosts.Length > 0) if (hosts.Length > 0)
{
foreach (IPAddress host in hosts)
{
if(host.AddressFamily == AddressFamily.InterNetwork)
return host;
}
// Well all else failed...
return hosts[0]; return hosts[0];
}
return null; return null;
} }