From 482d11cc3e34284f72b26028bcc41125d5b705fd Mon Sep 17 00:00:00 2001 From: Josh Dersch Date: Wed, 18 Nov 2020 00:01:15 -0800 Subject: [PATCH] Fixed gateway routing. You can now play Mazewar across the Internet, the way it was meant to be played. --- .gitignore | 3 ++ PUP/Entrypoint.cs | 4 +- PUP/Gateway/Router.cs | 96 ++++++++++++++++------------------ PUP/Properties/AssemblyInfo.cs | 6 +-- PUP/Transport/UDP.cs | 2 +- 5 files changed, 53 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index 96bd921..5aac385 100644 --- a/.gitignore +++ b/.gitignore @@ -191,3 +191,6 @@ ModelManifest.xml /PUP/.vs/IFS/v15/Server/sqlite3/storage.ide /PUP/.vs/IFS/v15/Server/sqlite3/storage.ide-shm /PUP/.vs/IFS/v15/Server/sqlite3/storage.ide-wal +/.vs/ProjectSettings.json +/.vs/slnx.sqlite +/.vs/VSWorkspaceState.json diff --git a/PUP/Entrypoint.cs b/PUP/Entrypoint.cs index 175d292..76abeaf 100644 --- a/PUP/Entrypoint.cs +++ b/PUP/Entrypoint.cs @@ -51,8 +51,8 @@ namespace IFS private static void PrintHerald() { - Console.WriteLine("LCM+L IFS v0.2, 12/14/2016."); - Console.WriteLine("(c) 2015-2017 Living Computers: Museum+Labs."); + Console.WriteLine("LCM+L IFS v0.3, 11/17/2020."); + Console.WriteLine("(c) 2015-2020 Living Computers: Museum+Labs."); Console.WriteLine("Bug reports to joshd@livingcomputers.org"); Console.WriteLine(); Console.WriteLine(); diff --git a/PUP/Gateway/Router.cs b/PUP/Gateway/Router.cs index f937947..cf7133d 100644 --- a/PUP/Gateway/Router.cs +++ b/PUP/Gateway/Router.cs @@ -264,11 +264,6 @@ namespace IFS.Gateway // if (p.DestinationPort.Network == DirectoryServices.Instance.LocalNetwork) { - // - // Send it out on the local network for anyone to see. - // - _pupPacketInterface.Send(p); - // // And if it's intended for us (the IFS server) let our services have a crack at it, too. // @@ -277,6 +272,15 @@ namespace IFS.Gateway { _localProtocolDispatcher.ReceivePUP(p); } + + // + // Send it out on the local network for anyone to see if it's not for us, or if it's a broadcast. + // + if (p.DestinationPort.Host != DirectoryServices.Instance.LocalHostAddress.Host || // not us + p.DestinationPort.Host == 0) // broadcast + { + _pupPacketInterface.Send(p); + } } else { @@ -325,7 +329,7 @@ namespace IFS.Gateway // properly.) Log.Write(LogComponent.Routing, "Gateway UDP Receiver thread started for port {0}.", _gatewayUdpPort); - IPEndPoint groupEndPoint = new IPEndPoint(IPAddress.Any, Configuration.UDPPort); + IPEndPoint groupEndPoint = new IPEndPoint(IPAddress.Any, _gatewayUdpPort); while (true) { @@ -347,58 +351,46 @@ namespace IFS.Gateway continue; } - - // 1) validate that the packet came in on the right port - // 2) validate packet - // 3) get a PUP out of it - // 4) send to RouteIncomingPacket. - // 5) do it again. - if (groupEndPoint.Port == _gatewayUdpPort) + + // 1) validate packet + // 2) get a PUP out of it + // 3) send to RouteIncomingPacket. + // 4) do it again. + if (data.Length < PUP.PUP_HEADER_SIZE + PUP.PUP_CHECKSUM_SIZE || + data.Length > PUP.MAX_PUP_SIZE + PUP.PUP_HEADER_SIZE + PUP.PUP_CHECKSUM_SIZE) { - if (data.Length < PUP.PUP_HEADER_SIZE + PUP.PUP_CHECKSUM_SIZE || - data.Length > PUP.MAX_PUP_SIZE + PUP.PUP_HEADER_SIZE + PUP.PUP_CHECKSUM_SIZE) - { - Log.Write(LogType.Error, LogComponent.Routing, "External PUP has an invalid size ({0}). Dropping.", data.Length); - continue; - } - - try - { - // - // See if we can get a PUP out of this. - // - PUP externalPUP = new PUP(new MemoryStream(data), data.Length); - - // - // TODO: should technically bump the PUP's TransportControl field up; - // really need to rewrite the PUP class to make this possible without - // building up an entirely new PUP. - // - RouteIncomingExternalPacket(externalPUP); - - Log.Write(LogType.Verbose, - LogComponent.Routing, - "<- External PUP received from {0}:{1}, type {2} source {3} destination {4}. Routing to local network.", - groupEndPoint.Address, - groupEndPoint.Port, - externalPUP.Type, - externalPUP.SourcePort, - externalPUP.DestinationPort); - } - catch (Exception e) - { - Log.Write(LogType.Error, LogComponent.Routing, "Error handling external PUP: {0}", e.Message); - } + Log.Write(LogType.Error, LogComponent.Routing, "External PUP has an invalid size ({0}). Dropping.", data.Length); + continue; } - else + + try { - Log.Write(LogType.Verbose, - LogComponent.Routing, - "Packet from {0} received on wrong port ({1}), expected {2}.", + // + // See if we can get a PUP out of this. + // + PUP externalPUP = new PUP(new MemoryStream(data), data.Length); + + // + // TODO: should technically bump the PUP's TransportControl field up; + // really need to rewrite the PUP class to make this possible without + // building up an entirely new PUP. + // + RouteIncomingExternalPacket(externalPUP); + + Log.Write(LogType.Verbose, + LogComponent.Routing, + "<- External PUP received from {0}:{1}, type {2} source {3} destination {4}. Routing to local network.", groupEndPoint.Address, groupEndPoint.Port, - _gatewayUdpPort); + externalPUP.Type, + externalPUP.SourcePort, + externalPUP.DestinationPort); } + catch (Exception e) + { + Log.Write(LogType.Error, LogComponent.Routing, "Error handling external PUP: {0}", e.Message); + } + } } diff --git a/PUP/Properties/AssemblyInfo.cs b/PUP/Properties/AssemblyInfo.cs index 5718a9e..b9cca8a 100644 --- a/PUP/Properties/AssemblyInfo.cs +++ b/PUP/Properties/AssemblyInfo.cs @@ -27,7 +27,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Living Computers: Museum+Labs")] [assembly: AssemblyProduct("IFS")] -[assembly: AssemblyCopyright("Copyright © LCM+L 2015-2017")] +[assembly: AssemblyCopyright("Copyright © LCM+L 2015-2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -49,5 +49,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0.0")] -[assembly: AssemblyFileVersion("1.2.0.0")] +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")] diff --git a/PUP/Transport/UDP.cs b/PUP/Transport/UDP.cs index 2c8b47c..31a1a8e 100644 --- a/PUP/Transport/UDP.cs +++ b/PUP/Transport/UDP.cs @@ -265,7 +265,7 @@ namespace IFS.Transport byte[] data = _udpClient.Receive(ref groupEndPoint); // Drop our own UDP packets. - if (!groupEndPoint.Address.Equals(_thisIPAddress)) + if (!groupEndPoint.Address.Equals(_thisIPAddress) && groupEndPoint.Port == Configuration.UDPPort) { Receive(new System.IO.MemoryStream(data)); }