1
0
mirror of https://github.com/livingcomputermuseum/IFS.git synced 2026-03-09 04:19:22 +00:00

Fixed gateway routing. You can now play Mazewar across the Internet, the way it was meant to be played.

This commit is contained in:
Josh Dersch
2020-11-18 00:01:15 -08:00
parent 97d92450b3
commit 482d11cc3e
5 changed files with 53 additions and 58 deletions

3
.gitignore vendored
View File

@@ -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

View File

@@ -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();

View File

@@ -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);
}
}
}

View File

@@ -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")]

View File

@@ -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));
}