]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Remove extraneous wrapper around IPEndpoint
authorForest <chocozilla@gmail.com>
Mon, 31 Dec 2018 03:55:01 +0000 (19:55 -0800)
committerForest <chocozilla@gmail.com>
Mon, 31 Dec 2018 03:55:45 +0000 (19:55 -0800)
Hazel.UnitTests/UdpConnectionTests.cs
Hazel.UnitTests/UnitTest1.cs
Hazel/Connection.cs
Hazel/ConnectionEndPoint.cs [deleted file]
Hazel/Hazel.csproj
Hazel/MessageWriter.cs
Hazel/NetworkEndPoint.cs [deleted file]
Hazel/Udp/UdpClientConnection.cs
Hazel/Udp/UdpConnectionListener.cs
Hazel/Udp/UdpServerConnection.cs

index 408eebd7d34baf37eb1f6627afeb05c716073cd7..a20118fa675e453c7ee0ed99dc9fdd352a593e6d 100644 (file)
@@ -17,9 +17,9 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpFieldTest()
         {
-            NetworkEndPoint ep = new NetworkEndPoint(IPAddress.Loopback, 4296);
+            IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, 4296);
 
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
             using (UdpConnection connection = new UdpClientConnection(ep))
             {
                 listener.Start();
@@ -40,8 +40,8 @@ namespace Hazel.UnitTests
         public void UdpHandshakeTest()
         {
             byte[] TestData = new byte[] { 1, 2, 3, 4, 5, 6 };
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296, IPMode.IPv4)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 listener.Start();
 
@@ -65,8 +65,8 @@ namespace Hazel.UnitTests
         public void UdpUnreliableMessageSendTest()
         {
             byte[] TestData = new byte[] { 1, 2, 3, 4, 5, 6 };
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296, IPMode.IPv4)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 MessageReader output = null;
                 listener.NewConnection += delegate (NewConnectionEventArgs e)
@@ -99,8 +99,8 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpUnreliableDataSubsetSendTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296, IPMode.IPv4)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 listener.Start();
                 listener.NewConnection += delegate (NewConnectionEventArgs e)
@@ -122,8 +122,8 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpIPv4ConnectionTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296, IPMode.IPv4)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296, IPMode.IPv4)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 listener.Start();
 
@@ -137,7 +137,7 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void MixedConnectionTest()
         {
-            using (UdpConnectionListener listener2 = new UdpConnectionListener(new NetworkEndPoint(IPAddress.IPv6Any, 4296, IPMode.IPv6)))
+            using (UdpConnectionListener listener2 = new UdpConnectionListener(new IPEndPoint(IPAddress.IPv6Any, 4296), IPMode.IPv6))
             {
                 listener2.Start();
 
@@ -146,13 +146,13 @@ namespace Hazel.UnitTests
                     Console.WriteLine("v6 connection: " + ((NetworkConnection)evt.Connection).GetIP4Address());
                 };
 
-                using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint("127.0.0.1", 4296, IPMode.IPv4)))
+                using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4296)))
                 {
                     connection.Connect();
                     Assert.AreEqual(ConnectionState.Connected, connection.State);
                 }
 
-                using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.IPv6Loopback, 4296, IPMode.IPv6)))
+                using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.IPv6Loopback, 4296), IPMode.IPv6))
                 {
                     connection.Connect();
                     Assert.AreEqual(ConnectionState.Connected, connection.State);
@@ -166,11 +166,11 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpIPv6ConnectionTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.IPv6Any, 4296, IPMode.IPv6)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.IPv6Any, 4296), IPMode.IPv6))
             {
                 listener.Start();
 
-                using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint("127.0.0.1", 4296, IPMode.IPv6)))
+                using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4296), IPMode.IPv6))
                 {
                     connection.Connect();
                 }
@@ -183,8 +183,8 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpUnreliableServerToClientTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunServerToClientTest(listener, connection, 10, SendOption.None);
             }
@@ -196,8 +196,8 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpReliableServerToClientTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunServerToClientTest(listener, connection, 10, SendOption.Reliable);
             }
@@ -209,8 +209,8 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpUnreliableClientToServerTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunClientToServerTest(listener, connection, 10, SendOption.None);
             }
@@ -222,8 +222,8 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void UdpReliableClientToServerTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunClientToServerTest(listener, connection, 10, SendOption.Reliable);
             }
@@ -235,8 +235,8 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void KeepAliveClientTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 listener.Start();
 
@@ -261,8 +261,8 @@ namespace Hazel.UnitTests
         {
             ManualResetEvent mutex = new ManualResetEvent(false);
 
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 listener.NewConnection += delegate(NewConnectionEventArgs args)
                 {
@@ -298,8 +298,8 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void ClientDisconnectTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunClientDisconnectTest(listener, connection);
             }
@@ -311,8 +311,8 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void ServerDisconnectTest()
         {
-            using (UdpConnectionListener listener = new UdpConnectionListener(new NetworkEndPoint(IPAddress.Any, 4296)))
-            using (UdpConnection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296)))
+            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
+            using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
             {
                 TestHelper.RunServerDisconnectTest(listener, connection);
             }
index 7b0eb6e1279c24b8c6869d914f2151fcf249d662..e1683ab1947c818fb6ced2bc790faccf599b4783 100644 (file)
@@ -13,7 +13,7 @@ namespace Hazel.UnitTests
         [TestMethod]
         public void StressTest()
         {
-            var ep = new NetworkEndPoint(IPAddress.Loopback, 22023);
+            var ep = new IPEndPoint(IPAddress.Loopback, 22023);
             Parallel.For(0, 10000,
                 new ParallelOptions { MaxDegreeOfParallelism = 64 },
                 (i) => {
index d300db129d4e0c988fd1efed06f5e07f702c79e4..5a8e99195c85a97e79bff713c42fe5d96e7fe013 100644 (file)
@@ -88,7 +88,9 @@ namespace Hazel
         ///     <see cref="ConnectionEndPoint"/> which can then be cast to an appropriate end point depending on the 
         ///     connection type.
         /// </remarks>
-        public ConnectionEndPoint EndPoint { get; protected set; }
+        public IPEndPoint EndPoint { get; protected set; }
+
+        public IPMode IPMode { get; protected set; }
 
         /// <summary>
         ///     The traffic statistics about this Connection.
diff --git a/Hazel/ConnectionEndPoint.cs b/Hazel/ConnectionEndPoint.cs
deleted file mode 100644 (file)
index 3e09537..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Hazel
-{
-    /// <summary>
-    ///     Base class for all end points of connections.
-    /// </summary>
-    /// <threadsafety static="true" instance="true"/>
-    public abstract class ConnectionEndPoint
-    {
-    }
-}
index 4f1be811597d45f20c4668066a104d8333e87c3a..b8027be789aee1c7155d598ffe0f0a1a7bf65044 100644 (file)
@@ -55,7 +55,6 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Connection.cs" />
-    <Compile Include="ConnectionEndPoint.cs" />
     <Compile Include="ConnectionListener.cs" />
     <Compile Include="ConnectionState.cs" />
     <Compile Include="DataReceivedEventArgs.cs" />
@@ -66,7 +65,6 @@
     <Compile Include="MessageReader.cs" />
     <Compile Include="NetworkConnection.cs" />
     <Compile Include="NetworkConnectionListener.cs" />
-    <Compile Include="NetworkEndPoint.cs" />
     <Compile Include="MessageWriter.cs" />
     <Compile Include="NewConnectionEventArgs.cs" />
     <Compile Include="ObjectPool.cs" />
index 01c3d9c55ea996af9c525bef9c5a28cef2037572..bbe12c28ac481e2e43037d47b07b8687a962e3d9 100644 (file)
@@ -11,7 +11,7 @@ namespace Hazel
         public static int BufferSize = 64000;
         public static readonly ObjectPool<MessageWriter> WriterPool = new ObjectPool<MessageWriter>(() => new MessageWriter(BufferSize));
 
-        internal byte[] Buffer;
+        public byte[] Buffer;
         public int Length;
         public int Position;
 
diff --git a/Hazel/NetworkEndPoint.cs b/Hazel/NetworkEndPoint.cs
deleted file mode 100644 (file)
index b6b6427..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-
-using System.Net;
-
-namespace Hazel
-{
-    /// <summary>
-    ///     Represents an endpoint to a remote resource on a network.
-    /// </summary>
-    /// <remarks>
-    ///     This wraps a <see cref="System.Net.EndPoint"/> for connecting across a network using protocols like TCP or UDP.
-    /// </remarks>
-    /// <threadsafety static="true" instance="true"/>
-    public sealed class NetworkEndPoint : ConnectionEndPoint
-    {
-        /// <summary>
-        ///     The <see cref="System.Net.EndPoint">EndPoint</see> this points to.
-        /// </summary>
-        public EndPoint EndPoint { get; set; }
-
-        /// <summary>
-        ///     The <see cref="IPMode"/> this will instruct connections to use.
-        /// </summary>
-        public IPMode IPMode { get; set; }
-
-        /// <summary>
-        ///     Creates a NetworkEndPoint from a given <see cref="System.Net.EndPoint">EndPoint</see>.
-        /// </summary>
-        /// <param name="endPoint">The end point to wrap.</param>
-        /// <param name="mode">The IP mode to use.</param>
-        public NetworkEndPoint(EndPoint endPoint, IPMode mode = IPMode.IPv4)
-        {
-            this.EndPoint = endPoint;
-            this.IPMode = mode;
-        }
-
-        /// <summary>
-        ///     Create a NetworkEndPoint to the specified <see cref="System.Net.IPAddress">IPAddress</see> and port.
-        /// </summary>
-        /// <param name="address">The IP address of the server.</param>
-        /// <param name="port">The port the server is listening on.</param>
-        /// <param name="mode">The IP mode to use.</param>
-        /// <remarks>
-        ///     When using this constructor <see cref="EndPoint"/> will contain an <see cref="IPEndPoint"/>.
-        /// </remarks>
-        public NetworkEndPoint(IPAddress address, int port, IPMode mode = IPMode.IPv4)
-            : this(new IPEndPoint(address, port), mode)
-        {
-
-        }
-
-        /// <summary>
-        ///     Creates a NetworkEndPoint to the specified IP address and port.
-        /// </summary>
-        /// <param name="IP">A valid IP address of the server.</param>
-        /// <param name="port">The port the server is listening on.</param>
-        /// <param name="mode">The IP mode to use.</param>
-        /// <remarks>
-        ///     When using this constructor <see cref="EndPoint"/> will contain an <see cref="IPEndPoint"/>.
-        /// </remarks>
-        public NetworkEndPoint(string IP, int port, IPMode mode = IPMode.IPv4)
-            : this(IPAddress.Parse(IP), port, mode)
-        {
-            
-        }
-
-        /// <inheritdoc />
-        public override string ToString()
-        {
-            return EndPoint.ToString();
-        }
-    }
-}
index 1a74a46e6038df3a40a74241cc0841cd70041d35..f4ccc1a240196753ecd7ba068f5d250a0dfebd06 100644 (file)
@@ -31,14 +31,14 @@ namespace Hazel.Udp
         ///     Creates a new UdpClientConnection.
         /// </summary>
         /// <param name="remoteEndPoint">A <see cref="NetworkEndPoint"/> to connect to.</param>
-        public UdpClientConnection(NetworkEndPoint remoteEndPoint)
+        public UdpClientConnection(IPEndPoint remoteEndPoint, IPMode ipMode = IPMode.IPv4)
             : base()
         {
             this.EndPoint = remoteEndPoint;
-            this.RemoteEndPoint = remoteEndPoint.EndPoint;
-            this.IPMode = remoteEndPoint.IPMode;
+            this.RemoteEndPoint = remoteEndPoint;
+            this.IPMode = ipMode;
 
-            if (remoteEndPoint.IPMode == IPMode.IPv4)
+            if (this.IPMode == IPMode.IPv4)
                 socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
             else
             {
index 7f251fa933ba338d967f47f1b5b21e2d82257497..75ea137935a510d8ce246ebe2925c36cf4a303e4 100644 (file)
@@ -40,13 +40,13 @@ namespace Hazel.Udp
         ///     Creates a new UdpConnectionListener for the given <see cref="IPAddress"/>, port and <see cref="IPMode"/>.
         /// </summary>
         /// <param name="endPoint">The endpoint to listen on.</param>
-        public UdpConnectionListener(NetworkEndPoint endPoint, Action<string> logger = null)
+        public UdpConnectionListener(IPEndPoint endPoint, IPMode ipMode = IPMode.IPv4, Action<string> logger = null)
         {
             this.Logger = logger;
-            this.EndPoint = endPoint.EndPoint;
-            this.IPMode = endPoint.IPMode;
+            this.EndPoint = endPoint;
+            this.IPMode = ipMode;
 
-            if (endPoint.IPMode == IPMode.IPv4)
+            if (this.IPMode == IPMode.IPv4)
                 this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
             else
             {
@@ -202,7 +202,7 @@ namespace Hazel.Udp
                     aware = this.allConnections.TryGetValue(remoteEndPoint, out connection);
                     if (!aware)
                     {
-                        connection = new UdpServerConnection(this, remoteEndPoint, this.IPMode);
+                        connection = new UdpServerConnection(this, (IPEndPoint)remoteEndPoint, this.IPMode);
                         if (!this.allConnections.TryAdd(remoteEndPoint, connection))
                         {
                             throw new Exception();
index 1b8847ecdc164a51d9e2a736e56f9d1a4e1f57e1..a9f56b3787ca184948ca02d1e6cf8f91d93d391b 100644 (file)
@@ -33,12 +33,12 @@ namespace Hazel.Udp
         /// <param name="listener">The listener that created this connection.</param>
         /// <param name="endPoint">The endpoint that we are connected to.</param>
         /// <param name="IPMode">The IPMode we are connected using.</param>
-        internal UdpServerConnection(UdpConnectionListener listener, EndPoint endPoint, IPMode IPMode)
+        internal UdpServerConnection(UdpConnectionListener listener, IPEndPoint endPoint, IPMode IPMode)
             : base()
         {
             this.Listener = listener;
             this.RemoteEndPoint = endPoint;
-            this.EndPoint = new NetworkEndPoint(endPoint);
+            this.EndPoint = endPoint;
             this.IPMode = IPMode;
 
             State = ConnectionState.Connected;