From: Forest Date: Mon, 31 Dec 2018 03:55:01 +0000 (-0800) Subject: Remove extraneous wrapper around IPEndpoint X-Git-Tag: 1.0.0~59 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=73c4a169bae92989ac1a480aefe3520a4ea7eca2;p=rhonda%2Fimpostor.hazel.git Remove extraneous wrapper around IPEndpoint --- diff --git a/Hazel.UnitTests/UdpConnectionTests.cs b/Hazel.UnitTests/UdpConnectionTests.cs index 408eebd..a20118f 100644 --- a/Hazel.UnitTests/UdpConnectionTests.cs +++ b/Hazel.UnitTests/UdpConnectionTests.cs @@ -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); } diff --git a/Hazel.UnitTests/UnitTest1.cs b/Hazel.UnitTests/UnitTest1.cs index 7b0eb6e..e1683ab 100644 --- a/Hazel.UnitTests/UnitTest1.cs +++ b/Hazel.UnitTests/UnitTest1.cs @@ -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) => { diff --git a/Hazel/Connection.cs b/Hazel/Connection.cs index d300db1..5a8e991 100644 --- a/Hazel/Connection.cs +++ b/Hazel/Connection.cs @@ -88,7 +88,9 @@ namespace Hazel /// which can then be cast to an appropriate end point depending on the /// connection type. /// - public ConnectionEndPoint EndPoint { get; protected set; } + public IPEndPoint EndPoint { get; protected set; } + + public IPMode IPMode { get; protected set; } /// /// The traffic statistics about this Connection. diff --git a/Hazel/ConnectionEndPoint.cs b/Hazel/ConnectionEndPoint.cs deleted file mode 100644 index 3e09537..0000000 --- a/Hazel/ConnectionEndPoint.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Hazel -{ - /// - /// Base class for all end points of connections. - /// - /// - public abstract class ConnectionEndPoint - { - } -} diff --git a/Hazel/Hazel.csproj b/Hazel/Hazel.csproj index 4f1be81..b8027be 100644 --- a/Hazel/Hazel.csproj +++ b/Hazel/Hazel.csproj @@ -55,7 +55,6 @@ - @@ -66,7 +65,6 @@ - diff --git a/Hazel/MessageWriter.cs b/Hazel/MessageWriter.cs index 01c3d9c..bbe12c2 100644 --- a/Hazel/MessageWriter.cs +++ b/Hazel/MessageWriter.cs @@ -11,7 +11,7 @@ namespace Hazel public static int BufferSize = 64000; public static readonly ObjectPool WriterPool = new ObjectPool(() => 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 index b6b6427..0000000 --- a/Hazel/NetworkEndPoint.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - - -using System.Net; - -namespace Hazel -{ - /// - /// Represents an endpoint to a remote resource on a network. - /// - /// - /// This wraps a for connecting across a network using protocols like TCP or UDP. - /// - /// - public sealed class NetworkEndPoint : ConnectionEndPoint - { - /// - /// The EndPoint this points to. - /// - public EndPoint EndPoint { get; set; } - - /// - /// The this will instruct connections to use. - /// - public IPMode IPMode { get; set; } - - /// - /// Creates a NetworkEndPoint from a given EndPoint. - /// - /// The end point to wrap. - /// The IP mode to use. - public NetworkEndPoint(EndPoint endPoint, IPMode mode = IPMode.IPv4) - { - this.EndPoint = endPoint; - this.IPMode = mode; - } - - /// - /// Create a NetworkEndPoint to the specified IPAddress and port. - /// - /// The IP address of the server. - /// The port the server is listening on. - /// The IP mode to use. - /// - /// When using this constructor will contain an . - /// - public NetworkEndPoint(IPAddress address, int port, IPMode mode = IPMode.IPv4) - : this(new IPEndPoint(address, port), mode) - { - - } - - /// - /// Creates a NetworkEndPoint to the specified IP address and port. - /// - /// A valid IP address of the server. - /// The port the server is listening on. - /// The IP mode to use. - /// - /// When using this constructor will contain an . - /// - public NetworkEndPoint(string IP, int port, IPMode mode = IPMode.IPv4) - : this(IPAddress.Parse(IP), port, mode) - { - - } - - /// - public override string ToString() - { - return EndPoint.ToString(); - } - } -} diff --git a/Hazel/Udp/UdpClientConnection.cs b/Hazel/Udp/UdpClientConnection.cs index 1a74a46..f4ccc1a 100644 --- a/Hazel/Udp/UdpClientConnection.cs +++ b/Hazel/Udp/UdpClientConnection.cs @@ -31,14 +31,14 @@ namespace Hazel.Udp /// Creates a new UdpClientConnection. /// /// A to connect to. - 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 { diff --git a/Hazel/Udp/UdpConnectionListener.cs b/Hazel/Udp/UdpConnectionListener.cs index 7f251fa..75ea137 100644 --- a/Hazel/Udp/UdpConnectionListener.cs +++ b/Hazel/Udp/UdpConnectionListener.cs @@ -40,13 +40,13 @@ namespace Hazel.Udp /// Creates a new UdpConnectionListener for the given , port and . /// /// The endpoint to listen on. - public UdpConnectionListener(NetworkEndPoint endPoint, Action logger = null) + public UdpConnectionListener(IPEndPoint endPoint, IPMode ipMode = IPMode.IPv4, Action 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(); diff --git a/Hazel/Udp/UdpServerConnection.cs b/Hazel/Udp/UdpServerConnection.cs index 1b8847e..a9f56b3 100644 --- a/Hazel/Udp/UdpServerConnection.cs +++ b/Hazel/Udp/UdpServerConnection.cs @@ -33,12 +33,12 @@ namespace Hazel.Udp /// The listener that created this connection. /// The endpoint that we are connected to. /// The IPMode we are connected using. - 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;