diff options
author | Adam Frisby | 2009-05-23 05:44:18 +0000 |
---|---|---|
committer | Adam Frisby | 2009-05-23 05:44:18 +0000 |
commit | 3b1b3ac9bbd77796a55bcc75d08f78bff5ca78af (patch) | |
tree | 3f9694631e41a4daf4465fea4a35bb966805d362 | |
parent | * NetworkUtil now handles an error case in a way which is easier to debug. (diff) | |
download | opensim-SC_OLD-3b1b3ac9bbd77796a55bcc75d08f78bff5ca78af.zip opensim-SC_OLD-3b1b3ac9bbd77796a55bcc75d08f78bff5ca78af.tar.gz opensim-SC_OLD-3b1b3ac9bbd77796a55bcc75d08f78bff5ca78af.tar.bz2 opensim-SC_OLD-3b1b3ac9bbd77796a55bcc75d08f78bff5ca78af.tar.xz |
* Breaks OpenSim.. err I mean.. adds NAT translation support to EnableSimulator EventQueue methods.
* NB: This may actually break logins on certain regions. Shake well before consuming.
3 files changed, 65 insertions, 1 deletions
diff --git a/OpenSim/Framework/NetworkUtil.cs b/OpenSim/Framework/NetworkUtil.cs index 759c52f..81e6cad 100644 --- a/OpenSim/Framework/NetworkUtil.cs +++ b/OpenSim/Framework/NetworkUtil.cs | |||
@@ -14,11 +14,49 @@ namespace OpenSim.Framework | |||
14 | /// This enables standard port forwarding techniques | 14 | /// This enables standard port forwarding techniques |
15 | /// to work correctly with OpenSim. | 15 | /// to work correctly with OpenSim. |
16 | /// </summary> | 16 | /// </summary> |
17 | static class NetworkUtil | 17 | public static class NetworkUtil |
18 | { | 18 | { |
19 | // IPv4Address, Subnet | 19 | // IPv4Address, Subnet |
20 | static readonly Dictionary<IPAddress,IPAddress> m_subnets = new Dictionary<IPAddress, IPAddress>(); | 20 | static readonly Dictionary<IPAddress,IPAddress> m_subnets = new Dictionary<IPAddress, IPAddress>(); |
21 | 21 | ||
22 | public static IPAddress GetIPFor(IPAddress user, IPAddress simulator) | ||
23 | { | ||
24 | // Check if we're accessing localhost. | ||
25 | foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName())) | ||
26 | { | ||
27 | if (host.Equals(user) && host.AddressFamily == AddressFamily.InterNetwork) | ||
28 | return host; | ||
29 | } | ||
30 | |||
31 | // Check for same LAN segment | ||
32 | foreach (KeyValuePair<IPAddress, IPAddress> subnet in m_subnets) | ||
33 | { | ||
34 | byte[] subnetBytes = subnet.Value.GetAddressBytes(); | ||
35 | byte[] localBytes = subnet.Key.GetAddressBytes(); | ||
36 | byte[] destBytes = user.GetAddressBytes(); | ||
37 | |||
38 | if (subnetBytes.Length != destBytes.Length || subnetBytes.Length != localBytes.Length) | ||
39 | return null; | ||
40 | |||
41 | bool valid = true; | ||
42 | |||
43 | for (int i = 0; i < subnetBytes.Length; i++) | ||
44 | { | ||
45 | if ((localBytes[i] & subnetBytes[i]) != (destBytes[i] & subnetBytes[i])) | ||
46 | { | ||
47 | valid = false; | ||
48 | break; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | if (valid) | ||
53 | return subnet.Key; | ||
54 | } | ||
55 | |||
56 | // Otherwise, return outside address | ||
57 | return simulator; | ||
58 | } | ||
59 | |||
22 | private static IPAddress GetExternalIPFor(IPAddress destination, string defaultHostname) | 60 | private static IPAddress GetExternalIPFor(IPAddress destination, string defaultHostname) |
23 | { | 61 | { |
24 | // Adds IPv6 Support (Not that any of the major protocols supports it...) | 62 | // Adds IPv6 Support (Not that any of the major protocols supports it...) |
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs index 542e7d0..7d55cc8 100644 --- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs +++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs | |||
@@ -33,6 +33,7 @@ using System.Threading; | |||
33 | using log4net; | 33 | using log4net; |
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Framework.Client; | ||
36 | using OpenSim.Framework.Communications; | 37 | using OpenSim.Framework.Communications; |
37 | using OpenSim.Framework.Communications.Cache; | 38 | using OpenSim.Framework.Communications.Cache; |
38 | using OpenSim.Framework.Communications.Capabilities; | 39 | using OpenSim.Framework.Communications.Capabilities; |
@@ -211,6 +212,14 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid | |||
211 | 212 | ||
212 | if (eq != null) | 213 | if (eq != null) |
213 | { | 214 | { |
215 | #region IP Translation for NAT | ||
216 | IClientIPEndpoint ipepClient; | ||
217 | if (avatar.ClientView.TryGet(out ipepClient)) | ||
218 | { | ||
219 | endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address); | ||
220 | } | ||
221 | #endregion | ||
222 | |||
214 | eq.EnableSimulator(realHandle, endPoint, avatar.UUID); | 223 | eq.EnableSimulator(realHandle, endPoint, avatar.UUID); |
215 | 224 | ||
216 | // ES makes the client send a UseCircuitCode message to the destination, | 225 | // ES makes the client send a UseCircuitCode message to the destination, |
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs index 0699552..85a3d96 100644 --- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs +++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs | |||
@@ -34,6 +34,7 @@ using OpenMetaverse; | |||
34 | using OpenMetaverse.StructuredData; | 34 | using OpenMetaverse.StructuredData; |
35 | using log4net; | 35 | using log4net; |
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Framework.Client; | ||
37 | using OpenSim.Framework.Communications; | 38 | using OpenSim.Framework.Communications; |
38 | using OpenSim.Framework.Communications.Cache; | 39 | using OpenSim.Framework.Communications.Cache; |
39 | using OpenSim.Framework.Communications.Capabilities; | 40 | using OpenSim.Framework.Communications.Capabilities; |
@@ -306,6 +307,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
306 | IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>(); | 307 | IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>(); |
307 | if (eq != null) | 308 | if (eq != null) |
308 | { | 309 | { |
310 | #region IP Translation for NAT | ||
311 | IClientIPEndpoint ipepClient; | ||
312 | if(avatar.ClientView.TryGet(out ipepClient)) | ||
313 | { | ||
314 | endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address); | ||
315 | } | ||
316 | #endregion | ||
317 | |||
309 | eq.EnableSimulator(reg.RegionHandle, endPoint, avatar.UUID); | 318 | eq.EnableSimulator(reg.RegionHandle, endPoint, avatar.UUID); |
310 | eq.EstablishAgentCommunication(avatar.UUID, endPoint, capsPath); | 319 | eq.EstablishAgentCommunication(avatar.UUID, endPoint, capsPath); |
311 | m_log.DebugFormat("[CAPS]: Sending new CAPS seed url {0} to client {1} in region {2}", | 320 | m_log.DebugFormat("[CAPS]: Sending new CAPS seed url {0} to client {1} in region {2}", |
@@ -812,6 +821,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
812 | 821 | ||
813 | if (eq != null) | 822 | if (eq != null) |
814 | { | 823 | { |
824 | #region IP Translation for NAT | ||
825 | IClientIPEndpoint ipepClient; | ||
826 | if (avatar.ClientView.TryGet(out ipepClient)) | ||
827 | { | ||
828 | endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address); | ||
829 | } | ||
830 | #endregion | ||
831 | |||
815 | eq.EnableSimulator(reg.RegionHandle, endPoint, avatar.UUID); | 832 | eq.EnableSimulator(reg.RegionHandle, endPoint, avatar.UUID); |
816 | 833 | ||
817 | // ES makes the client send a UseCircuitCode message to the destination, | 834 | // ES makes the client send a UseCircuitCode message to the destination, |