From: Forest Date: Sat, 11 Jan 2020 23:37:26 +0000 (-0800) Subject: Add some UPnP capabilities, add an intercept for internal disconnect messages X-Git-Tag: 1.0.0~32 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=b1c9941825481c18cb47b39453a1ed0444852cee;p=rhonda%2Fimpostor.hazel.git Add some UPnP capabilities, add an intercept for internal disconnect messages --- diff --git a/Hazel.UnitTests/Hazel.UnitTests.csproj b/Hazel.UnitTests/Hazel.UnitTests.csproj index 88f9a73..b2e55e3 100644 --- a/Hazel.UnitTests/Hazel.UnitTests.csproj +++ b/Hazel.UnitTests/Hazel.UnitTests.csproj @@ -64,6 +64,7 @@ + diff --git a/Hazel.UnitTests/UPnPTests.cs b/Hazel.UnitTests/UPnPTests.cs new file mode 100644 index 0000000..460740d --- /dev/null +++ b/Hazel.UnitTests/UPnPTests.cs @@ -0,0 +1,43 @@ +using System; +using Hazel.UPnP; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Hazel.UnitTests +{ + [TestClass] + public class UPnPTests + { + [TestMethod] + public void CanForwardPort() + { + using (UPnPHelper dut = new UPnPHelper(Logger.Instance)) + { + Assert.IsTrue(dut.ForwardPort(22023, "Hazel Test")); + } + } + + [TestMethod] + public void CanDeletePort() + { + using (UPnPHelper dut = new UPnPHelper(Logger.Instance)) + { + Assert.IsTrue(dut.DeleteForwardingRule(22023)); + } + } + } + + public class Logger : ILogger + { + public static readonly ILogger Instance = new Logger(); + + public void LogError(string msg) + { + Console.WriteLine(msg); + } + + public void LogInfo(string msg) + { + Console.WriteLine(msg); + } + } +} diff --git a/Hazel/ConnectionStatistics.cs b/Hazel/ConnectionStatistics.cs index 1e90105..32ad0a0 100644 --- a/Hazel/ConnectionStatistics.cs +++ b/Hazel/ConnectionStatistics.cs @@ -13,6 +13,8 @@ namespace Hazel /// public class ConnectionStatistics { + private const int ExpectedMTU = 1200; + /// /// The total number of messages sent. /// @@ -403,7 +405,7 @@ namespace Hazel Interlocked.Add(ref dataBytesSent, dataLength); Interlocked.Add(ref totalBytesSent, totalLength); - if (totalLength > 576) + if (totalLength > ExpectedMTU) { Interlocked.Increment(ref fragmentableMessagesSent); } @@ -423,7 +425,7 @@ namespace Hazel Interlocked.Add(ref dataBytesSent, dataLength); Interlocked.Add(ref totalBytesSent, totalLength); - if (totalLength > 1400) + if (totalLength > ExpectedMTU) { Interlocked.Increment(ref fragmentableMessagesSent); } @@ -443,7 +445,7 @@ namespace Hazel Interlocked.Add(ref dataBytesSent, dataLength); Interlocked.Add(ref totalBytesSent, totalLength); - if (totalLength > 1400) + if (totalLength > ExpectedMTU) { Interlocked.Increment(ref fragmentableMessagesSent); } diff --git a/Hazel/Hazel.csproj b/Hazel/Hazel.csproj index 0793714..7e81a65 100644 --- a/Hazel/Hazel.csproj +++ b/Hazel/Hazel.csproj @@ -96,7 +96,11 @@ + + + +