From 06a8c132005b4ab804f25d54c0c0f899fc98e3a1 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Sun, 1 Jul 2007 16:07:41 +0000 Subject: MAJOR IP RESTRUCTURING * moving towards IPEndPoints all over the place * trying to make the internal/external division --- OpenSim/Framework/Console/LogBase.cs | 58 ++++- OpenSim/Framework/General/Interfaces/IClientAPI.cs | 7 +- OpenSim/Framework/General/Types/RegionInfo.cs | 270 +++++++++++++-------- 3 files changed, 218 insertions(+), 117 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Console/LogBase.cs b/OpenSim/Framework/Console/LogBase.cs index 1a92d8e..a4a17e9 100644 --- a/OpenSim/Framework/Console/LogBase.cs +++ b/OpenSim/Framework/Console/LogBase.cs @@ -27,6 +27,7 @@ */ using System; using System.IO; +using System.Net; namespace OpenSim.Framework.Console { @@ -48,18 +49,18 @@ namespace OpenSim.Framework.Console public string componentname; private bool m_silent; - public LogBase(string LogFile, string componentname, conscmd_callback cmdparser, bool silent ) + public LogBase(string LogFile, string componentname, conscmd_callback cmdparser, bool silent) { this.componentname = componentname; this.cmdparser = cmdparser; this.m_silent = silent; System.Console.WriteLine("ServerConsole.cs - creating new local console"); - - if( String.IsNullOrEmpty( LogFile ) ) + + if (String.IsNullOrEmpty(LogFile)) { LogFile = componentname + ".log"; } - + System.Console.WriteLine("Logs will be saved to current directory in " + LogFile); Log = File.AppendText(LogFile); Log.WriteLine("========================================================================"); @@ -74,10 +75,10 @@ namespace OpenSim.Framework.Console public void Write(string format, params object[] args) { - Notice(format,args); + Notice(format, args); return; } - + public void WriteLine(LogPriority importance, string format, params object[] args) { Log.WriteLine(format, args); @@ -154,6 +155,49 @@ namespace OpenSim.Framework.Console return TempInt; } + public IPAddress CmdPromptIPAddress(string prompt, string defaultvalue) + { + IPAddress address; + string addressStr; + + while (true) + { + addressStr = OpenSim.Framework.Console.MainLog.Instance.CmdPrompt(prompt, defaultvalue); + if (IPAddress.TryParse(addressStr, out address)) + { + break; + } + else + { + OpenSim.Framework.Console.MainLog.Instance.Error("Illegal address. Please re-enter."); + } + } + + return address; + } + + public int CmdPromptIPPort(string prompt, string defaultvalue) + { + int port; + string portStr; + + while (true) + { + portStr = OpenSim.Framework.Console.MainLog.Instance.CmdPrompt(prompt, defaultvalue); + if (int.TryParse(portStr, out port)) + { + if (port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort) + { + break; + } + } + + OpenSim.Framework.Console.MainLog.Instance.Error("Illegal address. Please re-enter."); + } + + return port; + } + // Displays a prompt and waits for the user to enter a string, then returns that string // Done with no echo and suitable for passwords public string PasswdPrompt(string prompt) @@ -178,7 +222,7 @@ namespace OpenSim.Framework.Console // Displays a command prompt and returns a default value if the user simply presses enter public string CmdPrompt(string prompt, string defaultresponse) { - string temp = CmdPrompt(String.Format( "{0} [{1}]", prompt, defaultresponse )); + string temp = CmdPrompt(String.Format("{0} [{1}]", prompt, defaultresponse)); if (temp == "") { return defaultresponse; diff --git a/OpenSim/Framework/General/Interfaces/IClientAPI.cs b/OpenSim/Framework/General/Interfaces/IClientAPI.cs index 4e8ac1a..ea4c5c9 100644 --- a/OpenSim/Framework/General/Interfaces/IClientAPI.cs +++ b/OpenSim/Framework/General/Interfaces/IClientAPI.cs @@ -32,6 +32,7 @@ using OpenSim.Framework.Inventory; using libsecondlife; using libsecondlife.Packets; using OpenSim.Framework.Types; +using System.Net; namespace OpenSim.Framework.Interfaces { @@ -143,12 +144,12 @@ namespace OpenSim.Framework.Interfaces void SendLayerData(float[] map); void SendLayerData(int px, int py, float[] map); void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look); - void InformClientOfNeighbour(ulong neighbourHandle, System.Net.IPAddress neighbourIP, ushort neighbourPort); + void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint ); AgentCircuitData RequestClientInfo(); - void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, System.Net.IPAddress newRegionIP, ushort newRegionPort); + void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, IPEndPoint newRegionExternalEndPoint ); void SendMapBlock(List mapBlocks); void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags); - void SendRegionTeleport(ulong regionHandle, byte simAccess, string ipAddress, ushort ipPort, uint locationID, uint flags); + void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, uint locationID, uint flags); void SendTeleportCancel(); void SendTeleportLocationStart(); void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance); diff --git a/OpenSim/Framework/General/Types/RegionInfo.cs b/OpenSim/Framework/General/Types/RegionInfo.cs index 1ead3c4..d98dd60 100644 --- a/OpenSim/Framework/General/Types/RegionInfo.cs +++ b/OpenSim/Framework/General/Types/RegionInfo.cs @@ -33,6 +33,7 @@ using OpenSim.Framework.Interfaces; using OpenSim.Framework.Utilities; using OpenSim.Framework.Console; using libsecondlife; +using System.Net; namespace OpenSim.Framework.Types { @@ -41,6 +42,32 @@ namespace OpenSim.Framework.Types public LLUUID SimUUID = new LLUUID(); public string RegionName = ""; + private IPEndPoint m_internalEndPoint; + public IPEndPoint InternalEndPoint + { + get + { + return m_internalEndPoint; + } + } + + public IPEndPoint ExternalEndPoint + { + get + { + return new IPEndPoint( Dns.GetHostAddresses( m_externalHostName )[0], m_internalEndPoint.Port ); + } + } + + private string m_externalHostName; + public string ExternalHostName + { + get + { + return m_externalHostName; + } + } + private uint? m_regionLocX; public uint RegionLocX { @@ -81,43 +108,43 @@ namespace OpenSim.Framework.Types public string MasterAvatarLastName = ""; public string MasterAvatarSandboxPassword = ""; - private int? m_commsIPListenPort; + //private int? m_commsIPListenPort; - /// - /// Port used for listening (TCP and UDP) - /// - /// Seperate TCP and UDP - public int CommsIPListenPort - { - get - { - return m_commsIPListenPort.Value; - } - } - - private string m_commsIPListenAddr; - /// - /// Address used for internal listening (default: 0.0.0.0?) - /// - public string CommsIPListenAddr - { - get - { - return m_commsIPListenAddr; - } - } - - private string m_commsExternalAddress; - /// - /// Address used for external addressing (DNS or IP) - /// - public string CommsExternalAddress - { - get - { - return m_commsExternalAddress; - } - } + ///// + ///// Port used for listening (TCP and UDP) + ///// + ///// Seperate TCP and UDP + //public int CommsIPListenPort + //{ + // get + // { + // return m_commsIPListenPort.Value; + // } + //} + + //private string m_commsIPListenAddr; + ///// + ///// Address used for internal listening (default: 0.0.0.0?) + ///// + //public string CommsIPListenAddr + //{ + // get + // { + // return m_commsIPListenAddr; + // } + //} + + //private string m_commsExternalAddress; + ///// + ///// Address used for external addressing (DNS or IP) + ///// + //public string CommsExternalAddress + //{ + // get + // { + // return m_commsExternalAddress; + // } + //} public EstateSettings estateSettings; @@ -126,15 +153,19 @@ namespace OpenSim.Framework.Types { estateSettings = new EstateSettings(); } - - public RegionInfo( uint regionLocX, uint regionLocY, string simIp, int simPort, string simUri ) : this() + + public RegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri) + : this() { m_regionLocX = regionLocX; - m_regionLocY = regionLocY; - - m_commsIPListenAddr = simIp; - m_commsIPListenPort = simPort; - m_commsExternalAddress = simUri; + m_regionLocY = regionLocY; + + //m_commsIPListenAddr = simIp; + //m_commsIPListenPort = simPort; + //m_commsExternalAddress = simUri; + + m_internalEndPoint = internalEndPoint; + m_externalHostName = externalUri; } public void InitConfig(bool sandboxMode, IGenericConfig configData) @@ -195,7 +226,7 @@ namespace OpenSim.Framework.Types } m_regionHandle = null; - + // Local storage datastore attri = ""; attri = configData.GetAttribute("Datastore"); @@ -210,71 +241,67 @@ namespace OpenSim.Framework.Types this.DataStore = attri; } - //Sim Listen Port - attri = ""; - attri = configData.GetAttribute("SimListenPort"); - if (attri == "") - { - string port = OpenSim.Framework.Console.MainLog.Instance.CmdPrompt("UDP port for client connections", "9000"); - configData.SetAttribute("SimListenPort", port); - m_commsIPListenPort = Convert.ToInt32(port); - } - else - { - m_commsIPListenPort = Convert.ToInt32(attri); - } + IPAddress internalAddress = GetIPAddress(configData, "InternalIPAddress", "0.0.0.0", "Internal IP Address for UDP client connections"); + int internalPort = GetIPPort(configData, "InternalIPPort", "9000", "Internal IP Port for UDP client connections"); + m_internalEndPoint = new IPEndPoint(internalAddress, internalPort); + + m_externalHostName = MainLog.Instance.CmdPrompt("External Host Name", "localhost"); + + + + //Sim Listen Address - attri = ""; - attri = configData.GetAttribute("SimListenAddress"); - if (attri == "") - { - m_commsIPListenAddr = OpenSim.Framework.Console.MainLog.Instance.CmdPrompt("IP Address to listen on for client connections", "0.0.0.0"); - configData.SetAttribute("SimListenAddress", CommsIPListenAddr ); - } - else - { - // Probably belongs elsewhere, but oh well. - if (attri.Trim().StartsWith("SYSTEMIP")) - { - string localhostname = System.Net.Dns.GetHostName(); - System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(localhostname); - try - { - m_commsIPListenAddr = "0.0.0.0"; // Incase a IPv4 address isnt found - - foreach (System.Net.IPAddress ip in ips) - { - if (ip.AddressFamily.ToString() == System.Net.Sockets.ProtocolFamily.InterNetwork.ToString()) - { - m_commsIPListenAddr = ip.ToString(); - break; - } - } - } - catch (Exception) - { - m_commsIPListenAddr = "0.0.0.0"; // Use the default if we fail - } - } - else - { - m_commsIPListenAddr = attri; - } - } + //attri = ""; + //attri = configData.GetAttribute("SimListenAddress"); + //if (attri == "") + //{ + // m_commsIPListenAddr = OpenSim.Framework.Console.MainLog.Instance.CmdPrompt("IP Address to listen on for client connections", "0.0.0.0"); + // configData.SetAttribute("SimListenAddress", CommsIPListenAddr); + //} + //else + //{ + // // Probably belongs elsewhere, but oh well. + // if (attri.Trim().StartsWith("SYSTEMIP")) + // { + // string localhostname = System.Net.Dns.GetHostName(); + // System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(localhostname); + // try + // { + // m_commsIPListenAddr = "0.0.0.0"; // Incase a IPv4 address isnt found - // Sim External Address - attri = ""; - attri = configData.GetAttribute("SimExternalAddress"); - if (attri == "") - { - m_commsExternalAddress = OpenSim.Framework.Console.MainLog.Instance.CmdPrompt("IP or DNS address to send external clients to", "localhost"); - configData.SetAttribute("SimExternalAddress", CommsExternalAddress); - } - else - { - m_commsExternalAddress = attri; - } + // foreach (System.Net.IPAddress ip in ips) + // { + // if (ip.AddressFamily.ToString() == System.Net.Sockets.ProtocolFamily.InterNetwork.ToString()) + // { + // m_commsIPListenAddr = ip.ToString(); + // break; + // } + // } + // } + // catch (Exception) + // { + // m_commsIPListenAddr = "0.0.0.0"; // Use the default if we fail + // } + // } + // else + // { + // m_commsIPListenAddr = attri; + // } + //} + + //// Sim External Address + //attri = ""; + //attri = configData.GetAttribute("SimExternalAddress"); + //if (attri == "") + //{ + // m_commsExternalAddress = OpenSim.Framework.Console.MainLog.Instance.CmdPrompt("IP or DNS address to send external clients to", "localhost"); + // configData.SetAttribute("SimExternalAddress", CommsExternalAddress); + //} + //else + //{ + // m_commsExternalAddress = attri; + //} attri = ""; attri = configData.GetAttribute("TerrainFile"); @@ -357,9 +384,38 @@ namespace OpenSim.Framework.Types OpenSim.Framework.Console.MainLog.Instance.Verbose("Name: " + this.RegionName); OpenSim.Framework.Console.MainLog.Instance.Verbose("Region Location: [" + this.RegionLocX.ToString() + "," + this.RegionLocY + "]"); OpenSim.Framework.Console.MainLog.Instance.Verbose("Region Handle: " + this.RegionHandle.ToString()); - OpenSim.Framework.Console.MainLog.Instance.Verbose("Listening on IP: " + this.CommsIPListenAddr + ":" + this.CommsIPListenPort); + OpenSim.Framework.Console.MainLog.Instance.Verbose("Listening on IP end point: " + m_internalEndPoint.ToString() ); OpenSim.Framework.Console.MainLog.Instance.Verbose("Sandbox Mode? " + isSandbox.ToString()); } + + private IPAddress GetIPAddress(IGenericConfig configData, string attrName, string defaultvalue, string prompt) + { + string addressStr = configData.GetAttribute(attrName); + + IPAddress address; + + if (!IPAddress.TryParse(addressStr, out address)) + { + address = MainLog.Instance.CmdPromptIPAddress(prompt, defaultvalue); + configData.SetAttribute(attrName, address.ToString()); + } + return address; + } + + private int GetIPPort(IGenericConfig configData, string attrName, string defaultvalue, string prompt) + { + string portStr = configData.GetAttribute(attrName); + + int port; + + if (!int.TryParse(portStr, out port)) + { + port = MainLog.Instance.CmdPromptIPPort(prompt, defaultvalue); + configData.SetAttribute(attrName, port.ToString()); + } + + return port; + } } } -- cgit v1.1