aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Util.cs30
1 files changed, 25 insertions, 5 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 061743d..a3c7750 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -991,6 +991,8 @@ namespace OpenSim.Framework
991 return output.ToString(); 991 return output.ToString();
992 } 992 }
993 993
994 static ExpiringCache<string,IPAddress> dnscache = new ExpiringCache<string, IPAddress>();
995
994 /// <summary> 996 /// <summary>
995 /// Converts a URL to a IPAddress 997 /// Converts a URL to a IPAddress
996 /// </summary> 998 /// </summary>
@@ -1008,15 +1010,20 @@ namespace OpenSim.Framework
1008 /// <returns>An IP address, or null</returns> 1010 /// <returns>An IP address, or null</returns>
1009 public static IPAddress GetHostFromDNS(string dnsAddress) 1011 public static IPAddress GetHostFromDNS(string dnsAddress)
1010 { 1012 {
1011 // If it is already an IP, avoid possible broken mono from seeing it
1012 if(String.IsNullOrWhiteSpace(dnsAddress)) 1013 if(String.IsNullOrWhiteSpace(dnsAddress))
1013 return null; 1014 return null;
1014 1015
1015 IPAddress ia = null; 1016 IPAddress ia = null;
1017 if(dnscache.TryGetValue(dnsAddress, out ia) && ia != null)
1018 return ia;
1019
1020 ia = null;
1021 // If it is already an IP, don't let GetHostEntry see it
1016 if (IPAddress.TryParse(dnsAddress, out ia) && ia != null) 1022 if (IPAddress.TryParse(dnsAddress, out ia) && ia != null)
1017 { 1023 {
1018 if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any)) 1024 if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
1019 return null; 1025 return null;
1026 dnscache.AddOrUpdate(dnsAddress, ia, 300);
1020 return ia; 1027 return ia;
1021 } 1028 }
1022 1029
@@ -1027,7 +1034,7 @@ namespace OpenSim.Framework
1027 } 1034 }
1028 catch // (SocketException e) 1035 catch // (SocketException e)
1029 { 1036 {
1030 return null; 1037 return null;
1031 } 1038 }
1032 1039
1033 if(IPH == null || IPH.AddressList.Length == 0) 1040 if(IPH == null || IPH.AddressList.Length == 0)
@@ -1045,6 +1052,8 @@ namespace OpenSim.Framework
1045 break; 1052 break;
1046 } 1053 }
1047 } 1054 }
1055 if(ia != null)
1056 dnscache.AddOrUpdate(dnsAddress, ia, 300);
1048 return ia; 1057 return ia;
1049 } 1058 }
1050 1059
@@ -1071,14 +1080,22 @@ namespace OpenSim.Framework
1071 return null; 1080 return null;
1072 1081
1073 IPAddress ia = null; 1082 IPAddress ia = null;
1074 // If it is already an IP, avoid possible broken mono from seeing it 1083 if(dnscache.TryGetValue(hostname, out ia) && ia != null)
1084 return getEndPoint(ia, port);
1085
1086 ia = null;
1087
1088 // If it is already an IP, don't let GetHostEntry see it
1075 if (IPAddress.TryParse(hostname, out ia) && ia != null) 1089 if (IPAddress.TryParse(hostname, out ia) && ia != null)
1076 { 1090 {
1077 if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any)) 1091 if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
1078 return null; 1092 return null;
1093
1094 dnscache.AddOrUpdate(hostname, ia, 300);
1079 return getEndPoint(ia, port); 1095 return getEndPoint(ia, port);
1080 } 1096 }
1081 1097
1098
1082 IPHostEntry IPH; 1099 IPHostEntry IPH;
1083 try 1100 try
1084 { 1101 {
@@ -1086,7 +1103,7 @@ namespace OpenSim.Framework
1086 } 1103 }
1087 catch // (SocketException e) 1104 catch // (SocketException e)
1088 { 1105 {
1089 return null; 1106 return null;
1090 } 1107 }
1091 1108
1092 if(IPH == null || IPH.AddressList.Length == 0) 1109 if(IPH == null || IPH.AddressList.Length == 0)
@@ -1105,6 +1122,9 @@ namespace OpenSim.Framework
1105 } 1122 }
1106 } 1123 }
1107 1124
1125 if(ia != null)
1126 dnscache.AddOrUpdate(hostname, ia, 300);
1127
1108 return getEndPoint(ia,port); 1128 return getEndPoint(ia,port);
1109 } 1129 }
1110 1130