]> git.deb.at Git - rhonda/impostor.git/commitdiff
Revert hazel changes for easier merging with its upstream
authorjs6pak <kubastaron@hotmail.com>
Wed, 24 Mar 2021 18:53:01 +0000 (19:53 +0100)
committerjs6pak <kubastaron@hotmail.com>
Wed, 24 Mar 2021 18:53:01 +0000 (19:53 +0100)
26 files changed:
src/Impostor.Hazel/Connection.cs
src/Impostor.Hazel/ConnectionListener.cs
src/Impostor.Hazel/ConnectionState.cs
src/Impostor.Hazel/ConnectionStatistics.cs
src/Impostor.Hazel/DataReceivedEventArgs.cs
src/Impostor.Hazel/DisconnectedEventArgs.cs
src/Impostor.Hazel/HazelException.cs
src/Impostor.Hazel/IPMode.cs
src/Impostor.Hazel/IRecyclable.cs
src/Impostor.Hazel/Impostor.Hazel.csproj
src/Impostor.Hazel/MessageReader.cs
src/Impostor.Hazel/MessageWriter.cs
src/Impostor.Hazel/NetworkConnection.cs
src/Impostor.Hazel/NetworkConnectionListener.cs
src/Impostor.Hazel/NewConnectionEventArgs.cs
src/Impostor.Hazel/ObjectPoolCustom.cs
src/Impostor.Hazel/Udp/SendOptionInternal.cs
src/Impostor.Hazel/Udp/UdpBroadcastListener.cs
src/Impostor.Hazel/Udp/UdpBroadcaster.cs
src/Impostor.Hazel/Udp/UdpClientConnection.cs
src/Impostor.Hazel/Udp/UdpConnection.KeepAlive.cs
src/Impostor.Hazel/Udp/UdpConnection.Reliable.cs
src/Impostor.Hazel/Udp/UdpConnection.cs
src/Impostor.Hazel/Udp/UdpConnectionListener.cs
src/Impostor.Hazel/Udp/UdpConnectionRateLimit.cs
src/Impostor.Hazel/Udp/UdpServerConnection.cs

index 23d7f4b69ed9a7f17ff6c4a96239c8229fb2bdd1..dec8cfecb280e9d16b526abc3bb518dea733865f 100644 (file)
@@ -11,7 +11,7 @@ namespace Impostor.Hazel
     /// </summary>
     /// <remarks>
     ///     <para>
-    ///         Connection is the base class for all connections that Hazel can make. It provides common functionality and a
+    ///         Connection is the base class for all connections that Hazel can make. It provides common functionality and a 
     ///         standard interface to allow connections to be swapped easily.
     ///     </para>
     ///     <para>
@@ -29,7 +29,7 @@ namespace Impostor.Hazel
     ///         </list>
     ///     </para>
     /// </remarks>
-    /// <threadsafety static="true" instance="true" />
+    /// <threadsafety static="true" instance="true"/>
     public abstract class Connection : IDisposable
     {
         private static readonly ILogger Logger = Log.ForContext<Connection>();
@@ -39,34 +39,34 @@ namespace Impostor.Hazel
         /// </summary>
         /// <remarks>
         ///     <para>
-        ///         DataReceived is invoked everytime a message is received from the end point of this connection, the message
-        ///         that was received can be found in the <see cref="DataReceivedEventArgs" /> alongside other information from the
+        ///         DataReceived is invoked everytime a message is received from the end point of this connection, the message 
+        ///         that was received can be found in the <see cref="DataReceivedEventArgs"/> alongside other information from the 
         ///         event.
         ///     </para>
         ///     <include file="DocInclude/common.xml" path="docs/item[@name='Event_Thread_Safety_Warning']/*" />
         /// </remarks>
         /// <example>
-        ///     <code language="C#" source="DocInclude/TcpClientExample.cs" />
+        ///     <code language="C#" source="DocInclude/TcpClientExample.cs"/>
         /// </example>
         public Func<DataReceivedEventArgs, ValueTask> DataReceived;
 
         public int TestLagMs = -1;
         public int TestDropRate = 0;
         protected int testDropCount = 0;
-
+        
         /// <summary>
         ///     Called when the end point disconnects or an error occurs.
         /// </summary>
         /// <remarks>
         ///     <para>
-        ///         Disconnected is invoked when the connection is closed due to an exception occuring or because the remote
-        ///         end point disconnected. If it was invoked due to an exception occuring then the exception is available
-        ///         in the <see cref="DisconnectedEventArgs" /> passed with the event.
+        ///         Disconnected is invoked when the connection is closed due to an exception occuring or because the remote 
+        ///         end point disconnected. If it was invoked due to an exception occuring then the exception is available 
+        ///         in the <see cref="DisconnectedEventArgs"/> passed with the event.
         ///     </para>
         ///     <include file="DocInclude/common.xml" path="docs/item[@name='Event_Thread_Safety_Warning']/*" />
         /// </remarks>
         /// <example>
-        ///     <code language="C#" source="DocInclude/TcpClientExample.cs" />
+        ///     <code language="C#" source="DocInclude/TcpClientExample.cs"/>
         /// </example>
         public Func<DisconnectedEventArgs, ValueTask> Disconnected;
 
@@ -74,8 +74,8 @@ namespace Impostor.Hazel
         ///     The remote end point of this Connection.
         /// </summary>
         /// <remarks>
-        ///     This is the end point that this connection is connected to (i.e. the other device). This returns an abstract
-        ///     <see cref="ConnectionEndPoint" /> which can then be cast to an appropriate end point depending on the
+        ///     This is the end point that this connection is connected to (i.e. the other device). This returns an abstract 
+        ///     <see cref="ConnectionEndPoint"/> which can then be cast to an appropriate end point depending on the 
         ///     connection type.
         /// </remarks>
         public IPEndPoint EndPoint { get; protected set; }
@@ -95,7 +95,7 @@ namespace Impostor.Hazel
         /// </summary>
         /// <remarks>
         ///     All implementers should be aware that when this is set to ConnectionState.Connected it will
-        ///     release all threads that are blocked on <see cref="WaitOnConnect" />.
+        ///     release all threads that are blocked on <see cref="WaitOnConnect"/>.
         /// </remarks>
         public ConnectionState State
         {
@@ -103,7 +103,7 @@ namespace Impostor.Hazel
             {
                 return this._state;
             }
-
+            
             protected set
             {
                 this._state = value;
@@ -113,13 +113,13 @@ namespace Impostor.Hazel
 
         protected ConnectionState _state;
         protected virtual void SetState(ConnectionState state) { }
-
+        
         /// <summary>
         ///     Constructor that initializes the ConnecitonStatistics object.
         /// </summary>
         /// <remarks>
-        ///     This constructor initialises <see cref="Statistics" /> with empty statistics and sets <see cref="State" /> to
-        ///     <see cref="ConnectionState.NotConnected" />.
+        ///     This constructor initialises <see cref="Statistics"/> with empty statistics and sets <see cref="State"/> to 
+        ///     <see cref="ConnectionState.NotConnected"/>.
         /// </remarks>
         protected Connection()
         {
@@ -128,21 +128,21 @@ namespace Impostor.Hazel
         }
 
         /// <summary>
-        ///     Sends a number of bytes to the end point of the connection using the specified <see cref="MessageType" />.
+        ///     Sends a number of bytes to the end point of the connection using the specified <see cref="MessageType"/>.
         /// </summary>
         /// <param name="msg">The message to send.</param>
         /// <remarks>
         ///     <include file="DocInclude/common.xml" path="docs/item[@name='Connection_SendBytes_General']/*" />
         ///     <para>
         ///         The messageType parameter is only a request to use those options and the actual method used to send the
-        ///         data is up to the implementation. There are circumstances where this parameter may be ignored but in
+        ///         data is up to the implementation. There are circumstances where this parameter may be ignored but in 
         ///         general any implementer should aim to always follow the user's request.
         ///     </para>
         /// </remarks>
         public abstract ValueTask SendAsync(IMessageWriter msg);
 
         /// <summary>
-        ///     Sends a number of bytes to the end point of the connection using the specified <see cref="MessageType" />.
+        ///     Sends a number of bytes to the end point of the connection using the specified <see cref="MessageType"/>.
         /// </summary>
         /// <param name="bytes">The bytes of the message to send.</param>
         /// <param name="messageType">The option specifying how the message should be sent.</param>
@@ -150,7 +150,7 @@ namespace Impostor.Hazel
         ///     <include file="DocInclude/common.xml" path="docs/item[@name='Connection_SendBytes_General']/*" />
         ///     <para>
         ///         The messageType parameter is only a request to use those options and the actual method used to send the
-        ///         data is up to the implementation. There are circumstances where this parameter may be ignored but in
+        ///         data is up to the implementation. There are circumstances where this parameter may be ignored but in 
         ///         general any implementer should aim to always follow the user's request.
         ///     </para>
         /// </remarks>
@@ -167,9 +167,9 @@ namespace Impostor.Hazel
         ///     Invokes the DataReceived event.
         /// </summary>
         /// <param name="msg">The bytes received.</param>
-        /// <param name="messageType">The <see cref="MessageType" /> the message was received with.</param>
+        /// <param name="messageType">The <see cref="MessageType"/> the message was received with.</param>
         /// <remarks>
-        ///     Invokes the <see cref="DataReceived" /> event on this connection to alert subscribers a new message has been
+        ///     Invokes the <see cref="DataReceived"/> event on this connection to alert subscribers a new message has been
         ///     received. The bytes and the send option that the message was sent with should be passed in to give to the
         ///     subscribers.
         /// </remarks>
@@ -197,8 +197,8 @@ namespace Impostor.Hazel
         /// <param name="e">The exception, if any, that occurred to cause this.</param>
         /// <param name="reader">Extra disconnect data</param>
         /// <remarks>
-        ///     Invokes the <see cref="Disconnected" /> event to alert subscribres this connection has been disconnected either
-        ///     by the end point or because an error occurred. If an error occurred the error should be passed in in order to
+        ///     Invokes the <see cref="Disconnected"/> event to alert subscribres this connection has been disconnected either 
+        ///     by the end point or because an error occurred. If an error occurred the error should be passed in in order to 
         ///     pass to the subscribers, otherwise null can be passed in.
         /// </remarks>
         protected async ValueTask InvokeDisconnected(string e, IMessageReader reader)
@@ -219,11 +219,11 @@ namespace Impostor.Hazel
         }
 
         /// <summary>
-        ///     For times when you want to force the disconnect handler to fire as well as close it.
-        ///     If you only want to close it, just use Dispose.
+        /// For times when you want to force the disconnect handler to fire as well as close it.
+        /// If you only want to close it, just use Dispose.
         /// </summary>
         public abstract ValueTask Disconnect(string reason, MessageWriter writer = null);
-
+        
         /// <summary>
         ///     Disposes of this NetworkConnection.
         /// </summary>
index 6c2f942ffd467a742ab8dd9ca506be0a3d9bc74f..116f657e47d462ac85419292fd2f59bf53800d4d 100644 (file)
@@ -10,16 +10,16 @@ namespace Impostor.Hazel
     /// </summary>
     /// <remarks>
     ///     <para>
-    ///         ConnectionListeners are server side objects that listen for clients and create matching server side connections
+    ///         ConnectionListeners are server side objects that listen for clients and create matching server side connections 
     ///         for each client in a similar way to TCP does. These connections should be ready for communication immediately.
     ///     </para>
     ///     <para>
-    ///         Each time a client connects the <see cref="NewConnection" /> event will be invoked to alert all subscribers to
-    ///         the new connection. A disconnected event is then present on the <see cref="Connection" /> that is passed to the
+    ///         Each time a client connects the <see cref="NewConnection"/> event will be invoked to alert all subscribers to
+    ///         the new connection. A disconnected event is then present on the <see cref="Connection"/> that is passed to the
     ///         subscribers.
     ///     </para>
     /// </remarks>
-    /// <threadsafety static="true" instance="true" />
+    /// <threadsafety static="true" instance="true"/>
     public abstract class ConnectionListener : IAsyncDisposable
     {
         private static readonly ILogger Logger = Log.ForContext<ConnectionListener>();
@@ -29,18 +29,18 @@ namespace Impostor.Hazel
         /// </summary>
         /// <remarks>
         ///     <para>
-        ///         NewConnection is invoked each time a client connects to the listener. The
-        ///         <see cref="NewConnectionEventArgs" /> contains the new <see cref="Connection" /> for communication with this
+        ///         NewConnection is invoked each time a client connects to the listener. The 
+        ///         <see cref="NewConnectionEventArgs"/> contains the new <see cref="Connection"/> for communication with this
         ///         client.
         ///     </para>
         ///     <para>
-        ///         Hazel may or may not store connections so it is your responsibility to keep track and properly Dispose of
-        ///         connections to your server.
+        ///         Hazel may or may not store connections so it is your responsibility to keep track and properly Dispose of 
+        ///         connections to your server. 
         ///     </para>
         ///     <include file="DocInclude/common.xml" path="docs/item[@name='Event_Thread_Safety_Warning']/*" />
         /// </remarks>
         /// <example>
-        ///     <code language="C#" source="DocInclude/TcpListenerExample.cs" />
+        ///     <code language="C#" source="DocInclude/TcpListenerExample.cs"/>
         /// </example>
         public Func<NewConnectionEventArgs, ValueTask> NewConnection;
 
@@ -49,15 +49,15 @@ namespace Impostor.Hazel
         /// </summary>
         /// <remarks>
         ///     <para>
-        ///         This instructs the listener to begin listening for new clients connecting to the server. When a new client
-        ///         connects the <see cref="NewConnection" /> event will be invoked containing the connection to the new client.
+        ///         This instructs the listener to begin listening for new clients connecting to the server. When a new client 
+        ///         connects the <see cref="NewConnection"/> event will be invoked containing the connection to the new client.
         ///     </para>
         ///     <para>
-        ///         To stop listening you should call <see cref="DisposeAsync()" />.
+        ///         To stop listening you should call <see cref="DisposeAsync()"/>.
         ///     </para>
         /// </remarks>
         /// <example>
-        ///     <code language="C#" source="DocInclude/TcpListenerExample.cs" />
+        ///     <code language="C#" source="DocInclude/TcpListenerExample.cs"/>
         /// </example>
         public abstract Task StartAsync();
 
@@ -67,7 +67,7 @@ namespace Impostor.Hazel
         /// <param name="msg">The user sent bytes that were received as part of the handshake.</param>
         /// <param name="connection">The connection to pass in the arguments.</param>
         /// <remarks>
-        ///     Implementers should call this to invoke the <see cref="NewConnection" /> event before data is received so that
+        ///     Implementers should call this to invoke the <see cref="NewConnection"/> event before data is received so that
         ///     subscribers do not miss any data that may have been sent immediately after connecting.
         /// </remarks>
         internal async Task InvokeNewConnection(IMessageReader msg, Connection connection)
index c9fd4de0f9c97be599a23629774a030216c8f552..5dd7c6a0767bcfc28fd90de26a92cd4a53f80620 100644 (file)
@@ -1,7 +1,7 @@
 ï»¿namespace Impostor.Hazel
 {
     /// <summary>
-    ///     Represents the state a <see cref="Connection" /> is currently in.
+    ///     Represents the state a <see cref="Connection"/> is currently in.
     /// </summary>
     public enum ConnectionState
     {
@@ -9,7 +9,7 @@
         ///     The Connection has either not been established yet or has been disconnected.
         /// </summary>
         NotConnected,
-
+        
         /// <summary>
         ///     The Connection is currently connecting to an endpoint.
         /// </summary>
index cd7567cf01ac962930e870b58462012bf6b51c88..48026208e24a3af5a8cce446874842cfc9e36727 100644 (file)
@@ -2,13 +2,12 @@
 using System.Threading;
 
 [assembly: InternalsVisibleTo("Hazel.Tests")]
-
 namespace Impostor.Hazel
 {
     /// <summary>
-    ///     Holds statistics about the traffic through a <see cref="Connection" />.
+    ///     Holds statistics about the traffic through a <see cref="Connection"/>.
     /// </summary>
-    /// <threadsafety static="true" instance="true" />
+    /// <threadsafety static="true" instance="true"/>
     public class ConnectionStatistics
     {
         private const int ExpectedMTU = 1200;
@@ -28,8 +27,8 @@ namespace Impostor.Hazel
         ///     The number of messages sent larger than 576 bytes. This is smaller than most default MTUs.
         /// </summary>
         /// <remarks>
-        ///     This is the number of unreliable messages that were sent from the <see cref="Connection" />, incremented
-        ///     each time that LogUnreliableSend is called by the Connection. Messages that caused an error are not
+        ///     This is the number of unreliable messages that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogUnreliableSend is called by the Connection. Messages that caused an error are not 
         ///     counted and messages are only counted once all other operations in the send are complete.
         /// </remarks>
         public int FragmentableMessagesSent
@@ -49,8 +48,8 @@ namespace Impostor.Hazel
         ///     The number of unreliable messages sent.
         /// </summary>
         /// <remarks>
-        ///     This is the number of unreliable messages that were sent from the <see cref="Connection" />, incremented
-        ///     each time that LogUnreliableSend is called by the Connection. Messages that caused an error are not
+        ///     This is the number of unreliable messages that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogUnreliableSend is called by the Connection. Messages that caused an error are not 
         ///     counted and messages are only counted once all other operations in the send are complete.
         /// </remarks>
         public int UnreliableMessagesSent
@@ -70,8 +69,8 @@ namespace Impostor.Hazel
         ///     The number of reliable messages sent.
         /// </summary>
         /// <remarks>
-        ///     This is the number of reliable messages that were sent from the <see cref="Connection" />, incremented
-        ///     each time that LogReliableSend is called by the Connection. Messages that caused an error are not
+        ///     This is the number of reliable messages that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogReliableSend is called by the Connection. Messages that caused an error are not 
         ///     counted and messages are only counted once all other operations in the send are complete.
         /// </remarks>
         public int ReliableMessagesSent
@@ -91,8 +90,8 @@ namespace Impostor.Hazel
         ///     The number of fragmented messages sent.
         /// </summary>
         /// <remarks>
-        ///     This is the number of fragmented messages that were sent from the <see cref="Connection" />, incremented
-        ///     each time that LogFragmentedSend is called by the Connection. Messages that caused an error are not
+        ///     This is the number of fragmented messages that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogFragmentedSend is called by the Connection. Messages that caused an error are not 
         ///     counted and messages are only counted once all other operations in the send are complete.
         /// </remarks>
         public int FragmentedMessagesSent
@@ -112,8 +111,8 @@ namespace Impostor.Hazel
         ///     The number of acknowledgement messages sent.
         /// </summary>
         /// <remarks>
-        ///     This is the number of acknowledgements that were sent from the <see cref="Connection" />, incremented
-        ///     each time that LogAcknowledgementSend is called by the Connection. Messages that caused an error are not
+        ///     This is the number of acknowledgements that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogAcknowledgementSend is called by the Connection. Messages that caused an error are not 
         ///     counted and messages are only counted once all other operations in the send are complete.
         /// </remarks>
         public int AcknowledgementMessagesSent
@@ -133,8 +132,8 @@ namespace Impostor.Hazel
         ///     The number of hello messages sent.
         /// </summary>
         /// <remarks>
-        ///     This is the number of hello messages that were sent from the <see cref="Connection" />, incremented
-        ///     each time that LogHelloSend is called by the Connection. Messages that caused an error are not
+        ///     This is the number of hello messages that were sent from the <see cref="Connection"/>, incremented 
+        ///     each time that LogHelloSend is called by the Connection. Messages that caused an error are not 
         ///     counted and messages are only counted once all other operations in the send are complete.
         /// </remarks>
         public int HelloMessagesSent
@@ -155,12 +154,12 @@ namespace Impostor.Hazel
         /// </summary>
         /// <remarks>
         ///     <para>
-        ///         This is the number of bytes of data (i.e. user bytes) that were sent from the <see cref="Connection" />,
-        ///         accumulated each time that LogSend is called by the Connection. Messages that caused an error are not
+        ///         This is the number of bytes of data (i.e. user bytes) that were sent from the <see cref="Connection"/>, 
+        ///         accumulated each time that LogSend is called by the Connection. Messages that caused an error are not 
         ///         counted and messages are only counted once all other operations in the send are complete.
         ///     </para>
         ///     <para>
-        ///         For the number of bytes including protocol bytes see <see cref="TotalBytesSent" />.
+        ///         For the number of bytes including protocol bytes see <see cref="TotalBytesSent"/>.
         ///     </para>
         /// </remarks>
         public long DataBytesSent
@@ -181,13 +180,13 @@ namespace Impostor.Hazel
         /// </summary>
         /// <remarks>
         ///     <para>
-        ///         This is the total number of bytes (the data bytes plus protocol bytes) that were sent from the
-        ///         <see cref="Connection" />, accumulated each time that LogSend is called by the Connection. Messages that
-        ///         caused an error are not counted and messages are only counted once all other operations in the send are
+        ///         This is the total number of bytes (the data bytes plus protocol bytes) that were sent from the 
+        ///         <see cref="Connection"/>, accumulated each time that LogSend is called by the Connection. Messages that 
+        ///         caused an error are not counted and messages are only counted once all other operations in the send are 
         ///         complete.
         ///     </para>
         ///     <para>
-        ///         For the number of data bytes excluding protocol bytes see <see cref="DataBytesSent" />.
+        ///         For the number of data bytes excluding protocol bytes see <see cref="DataBytesSent"/>.
         ///     </para>
         /// </remarks>
         public long TotalBytesSent
@@ -213,12 +212,12 @@ namespace Impostor.Hazel
                 return UnreliableMessagesReceived + ReliableMessagesReceived + FragmentedMessagesReceived + AcknowledgementMessagesReceived + helloMessagesReceived;
             }
         }
-
+        
         /// <summary>
         ///     The number of unreliable messages received.
         /// </summary>
         /// <remarks>
-        ///     This is the number of unreliable messages that were received by the <see cref="Connection" />, incremented
+        ///     This is the number of unreliable messages that were received by the <see cref="Connection"/>, incremented
         ///     each time that LogUnreliableReceive is called by the Connection. Messages are counted before the receive event is invoked.
         /// </remarks>
         public int UnreliableMessagesReceived
@@ -238,7 +237,7 @@ namespace Impostor.Hazel
         ///     The number of reliable messages received.
         /// </summary>
         /// <remarks>
-        ///     This is the number of reliable messages that were received by the <see cref="Connection" />, incremented
+        ///     This is the number of reliable messages that were received by the <see cref="Connection"/>, incremented
         ///     each time that LogReliableReceive is called by the Connection. Messages are counted before the receive event is invoked.
         /// </remarks>
         public int ReliableMessagesReceived
@@ -258,7 +257,7 @@ namespace Impostor.Hazel
         ///     The number of fragmented messages received.
         /// </summary>
         /// <remarks>
-        ///     This is the number of fragmented messages that were received by the <see cref="Connection" />, incremented
+        ///     This is the number of fragmented messages that were received by the <see cref="Connection"/>, incremented
         ///     each time that LogFragmentedReceive is called by the Connection. Messages are counted before the receive event is invoked.
         /// </remarks>
         public int FragmentedMessagesReceived
@@ -278,7 +277,7 @@ namespace Impostor.Hazel
         ///     The number of acknowledgement messages received.
         /// </summary>
         /// <remarks>
-        ///     This is the number of acknowledgement messages that were received by the <see cref="Connection" />, incremented
+        ///     This is the number of acknowledgement messages that were received by the <see cref="Connection"/>, incremented
         ///     each time that LogAcknowledgemntReceive is called by the Connection. Messages are counted before the receive event is invoked.
         /// </remarks>
         public int AcknowledgementMessagesReceived
@@ -298,7 +297,7 @@ namespace Impostor.Hazel
         ///     The number of ping messages received.
         /// </summary>
         /// <remarks>
-        ///     This is the number of hello messages that were received by the <see cref="Connection" />, incremented
+        ///     This is the number of hello messages that were received by the <see cref="Connection"/>, incremented
         ///     each time that LogHelloReceive is called by the Connection. Messages are counted before the receive event is invoked.
         /// </remarks>
         public int PingMessagesReceived
@@ -318,7 +317,7 @@ namespace Impostor.Hazel
         ///     The number of hello messages received.
         /// </summary>
         /// <remarks>
-        ///     This is the number of hello messages that were received by the <see cref="Connection" />, incremented
+        ///     This is the number of hello messages that were received by the <see cref="Connection"/>, incremented
         ///     each time that LogHelloReceive is called by the Connection. Messages are counted before the receive event is invoked.
         /// </remarks>
         public int HelloMessagesReceived
@@ -339,12 +338,12 @@ namespace Impostor.Hazel
         /// </summary>
         /// <remarks>
         ///     <para>
-        ///         This is the number of bytes of data (i.e. user bytes) that were received by the <see cref="Connection" />,
+        ///         This is the number of bytes of data (i.e. user bytes) that were received by the <see cref="Connection"/>, 
         ///         accumulated each time that LogReceive is called by the Connection. Messages are counted before the receive
         ///         event is invoked.
         ///     </para>
         ///     <para>
-        ///         For the number of bytes including protocol bytes see <see cref="TotalBytesReceived" />.
+        ///         For the number of bytes including protocol bytes see <see cref="TotalBytesReceived"/>.
         ///     </para>
         /// </remarks>
         public long DataBytesReceived
@@ -365,12 +364,12 @@ namespace Impostor.Hazel
         /// </summary>
         /// <remarks>
         ///     <para>
-        ///         This is the total number of bytes (the data bytes plus protocol bytes) that were received by the
-        ///         <see cref="Connection" />, accumulated each time that LogReceive is called by the Connection. Messages are
+        ///         This is the total number of bytes (the data bytes plus protocol bytes) that were received by the 
+        ///         <see cref="Connection"/>, accumulated each time that LogReceive is called by the Connection. Messages are 
         ///         counted before the receive event is invoked.
         ///     </para>
         ///     <para>
-        ///         For the number of data bytes excluding protocol bytes see <see cref="DataBytesReceived" />.
+        ///         For the number of data bytes excluding protocol bytes see <see cref="DataBytesReceived"/>.
         ///     </para>
         /// </remarks>
         public long TotalBytesReceived
index d2259e58eca59440c6ccfb965da38017f74b0c9f..9176d8d935ec88dd32897cce5d31eab7ac28bc9a 100644 (file)
@@ -12,10 +12,10 @@ namespace Impostor.Hazel
         public readonly IMessageReader Message;
 
         /// <summary>
-        ///     The <see cref="Type" /> the data was sent with.
+        ///     The <see cref="Type"/> the data was sent with.
         /// </summary>
         public readonly MessageType Type;
-
+        
         public DataReceivedEventArgs(Connection sender, IMessageReader msg, MessageType type)
         {
             this.Sender = sender;
index 4872aea9785b79116d55850ea18dd32fe2ce57f3..d46df4b9c9a319e5ea4925eaf16fc2a53af83dcd 100644 (file)
@@ -6,13 +6,13 @@ namespace Impostor.Hazel
     public class DisconnectedEventArgs : EventArgs
     {
         /// <summary>
-        ///     Optional disconnect reason. May be null.
+        /// Optional disconnect reason. May be null.
         /// </summary>
         public readonly string Reason;
 
         /// <summary>
-        ///     Optional data sent with a disconnect message. May be null.
-        ///     You must not recycle this. If you need the message outside of a callback, you should copy it.
+        /// Optional data sent with a disconnect message. May be null. 
+        /// You must not recycle this. If you need the message outside of a callback, you should copy it.
         /// </summary>
         public readonly IMessageReader Message;
 
index 81c8017a89b9d2eae0f6a542551b9fe28e367c9b..8c6fc3c12984200a0e2493611e4154fd4ee72347 100644 (file)
@@ -8,12 +8,14 @@ namespace Impostor.Hazel
     [Serializable]
     public class HazelException : Exception
     {
-        internal HazelException(string msg) : base(msg)
+        internal HazelException(string msg) : base (msg)
         {
+
         }
 
-        internal HazelException(string msg, Exception e) : base(msg, e)
+        internal HazelException(string msg, Exception e) : base (msg, e)
         {
+
         }
     }
 }
index 3f4395841ceead40528370f4a0c4d73fd3c84a55..5eb6679e56b417c1f334359d068df858b85f5a97 100644 (file)
@@ -4,8 +4,8 @@
     ///     Represents the IP version that a connection or listener will use.
     /// </summary>
     /// <remarks>
-    ///     If you wand a client to connect or be able to connect using IPv6 then you should use <see cref="IPv4AndIPv6" />,
-    ///     this sets the underlying sockets to use IPv6 but still allow IPv4 sockets to connect for backwards compatability
+    ///     If you wand a client to connect or be able to connect using IPv6 then you should use <see cref="IPv4AndIPv6"/>, 
+    ///     this sets the underlying sockets to use IPv6 but still allow IPv4 sockets to connect for backwards compatability 
     ///     and hence it is the default IPMode in most cases.
     /// </remarks>
     public enum IPMode
@@ -16,9 +16,9 @@
         IPv4,
 
         /// <summary>
-        ///     Instruction to use IPv6 only, IPv4 connections will not be able to connect. IPv4 addresses can be connected
+        ///     Instruction to use IPv6 only, IPv4 connections will not be able to connect. IPv4 addresses can be connected 
         ///     by converting to IPv6 addresses.
         /// </summary>
-        IPv6,
+        IPv6
     }
 }
index 0ddc04cd1b143748115c91d2c4b36c643b26cb71..69be1225b5580a158ba0ff209499d95344b65269 100644 (file)
@@ -3,7 +3,7 @@
     /// <summary>
     ///     Interface for all items that can be returned to an object pool.
     /// </summary>
-    /// <threadsafety static="true" instance="true" />
+    /// <threadsafety static="true" instance="true"/>
     public interface IRecyclable
     {
         /// <summary>
index 7ab52af6fbcde0930b6f4115cec3059ce04febdf..00997697c8109d0db4e4c5e3a121f967ee6c5c84 100644 (file)
@@ -1,18 +1,18 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
-  <PropertyGroup>
-    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <TargetFramework>net5.0</TargetFramework>
-    <DefineConstants>HAZEL_BAG</DefineConstants>
-  </PropertyGroup>
+    <PropertyGroup>
+        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+        <TargetFramework>net5.0</TargetFramework>
+        <DefineConstants>HAZEL_BAG</DefineConstants>
+    </PropertyGroup>
 
-  <ItemGroup>
-    <PackageReference Include="Microsoft.Extensions.ObjectPool" Version="5.0.4" />
-    <PackageReference Include="Serilog" Version="2.10.0" />
-  </ItemGroup>
+    <ItemGroup>
+        <PackageReference Include="Microsoft.Extensions.ObjectPool" Version="5.0.0" />
+        <PackageReference Include="Serilog" Version="2.10.0" />
+    </ItemGroup>
 
-  <ItemGroup>
-    <ProjectReference Include="..\Impostor.Api\Impostor.Api.csproj" />
-  </ItemGroup>
+    <ItemGroup>
+      <ProjectReference Include="..\Impostor.Api\Impostor.Api.csproj" />
+    </ItemGroup>
 
 </Project>
index 969e41b04d0305c1b0fd3a35e0ce1d5094903b56..317e45b1ee1a2c2898ebe5e5bf5ab5ba470370e5 100644 (file)
@@ -78,7 +78,7 @@ namespace Impostor.Hazel
 
         public bool ReadBoolean()
         {
-            var val = FastByte();
+            byte val = FastByte();
             return val != 0;
         }
 
@@ -159,13 +159,13 @@ namespace Impostor.Hazel
 
         public uint ReadPackedUInt32()
         {
-            var readMore = true;
-            var shift = 0;
+            bool readMore = true;
+            int shift = 0;
             uint output = 0;
 
             while (readMore)
             {
-                var b = FastByte();
+                byte b = FastByte();
                 if (b >= 0x80)
                 {
                     readMore = true;
@@ -185,8 +185,8 @@ namespace Impostor.Hazel
 
         public void CopyTo(IMessageWriter writer)
         {
-            writer.Write((ushort)Length);
-            writer.Write((byte)Tag);
+            writer.Write((ushort) Length);
+            writer.Write((byte) Tag);
             writer.Write(Buffer.AsMemory(Offset, Length));
         }
 
@@ -213,7 +213,7 @@ namespace Impostor.Hazel
 
             System.Buffer.BlockCopy(Buffer, offsetEnd, Buffer, offsetStart, lengthToCopy);
 
-            ((MessageReader)message).Parent.AdjustLength(message.Offset, message.Length + 3);
+            ((MessageReader) message).Parent.AdjustLength(message.Offset, message.Length + 3);
         }
 
         private void AdjustLength(int offset, int amount)
@@ -255,9 +255,9 @@ namespace Impostor.Hazel
         public Vector2 ReadVector2()
         {
             const float range = 50f;
-
-            var x = ReadUInt16() / (float)ushort.MaxValue;
-            var y = ReadUInt16() / (float)ushort.MaxValue;
+            
+            var x = ReadUInt16() / (float) ushort.MaxValue;
+            var y = ReadUInt16() / (float) ushort.MaxValue;
 
             return new Vector2(Mathf.Lerp(-range, range, x), Mathf.Lerp(-range, range, y));
         }
index bb71a71b50a3008ca44de2cce22ce7b8a57052ec..a7b57e78e7c3e3ea599dc824d6d959f0efda6364 100644 (file)
@@ -1,11 +1,12 @@
-using System;
+using Impostor.Api.Games;
+using Impostor.Api.Net.Messages;
+
+using System;
 using System.Collections.Generic;
 using System.Net;
 using System.Numerics;
 using System.Text;
-using Impostor.Api.Games;
 using Impostor.Api.Net.Inner;
-using Impostor.Api.Net.Messages;
 using Impostor.Api.Unity;
 
 namespace Impostor.Hazel
@@ -38,7 +39,7 @@ namespace Impostor.Hazel
         {
             if (includeHeader)
             {
-                var output = new byte[this.Length];
+                byte[] output = new byte[this.Length];
                 System.Buffer.BlockCopy(this.Buffer, 0, output, 0, this.Length);
                 return output;
             }
@@ -47,17 +48,17 @@ namespace Impostor.Hazel
                 switch (this.SendOption)
                 {
                     case MessageType.Reliable:
-                    {
-                        var output = new byte[this.Length - 3];
-                        System.Buffer.BlockCopy(this.Buffer, 3, output, 0, this.Length - 3);
-                        return output;
-                    }
+                        {
+                            byte[] output = new byte[this.Length - 3];
+                            System.Buffer.BlockCopy(this.Buffer, 3, output, 0, this.Length - 3);
+                            return output;
+                        }
                     case MessageType.Unreliable:
-                    {
-                        var output = new byte[this.Length - 1];
-                        System.Buffer.BlockCopy(this.Buffer, 1, output, 0, this.Length - 1);
-                        return output;
-                    }
+                        {
+                            byte[] output = new byte[this.Length - 1];
+                            System.Buffer.BlockCopy(this.Buffer, 1, output, 0, this.Length - 1);
+                            return output;
+                        }
                     default:
                         throw new ArgumentOutOfRangeException();
                 }
@@ -66,6 +67,7 @@ namespace Impostor.Hazel
             throw new NotImplementedException();
         }
 
+        ///
         /// <param name="sendOption">The option specifying how the message should be sent.</param>
         public static MessageWriter Get(MessageType sendOption = MessageType.Unreliable)
         {
@@ -104,8 +106,8 @@ namespace Impostor.Hazel
 
         public void Write(Vector2 vector)
         {
-            Write((ushort)(Mathf.ReverseLerp(vector.X) * (double)ushort.MaxValue));
-            Write((ushort)(Mathf.ReverseLerp(vector.Y) * (double)ushort.MaxValue));
+            Write((ushort)(Mathf.ReverseLerp(vector.X) * (double) ushort.MaxValue));
+            Write((ushort)(Mathf.ReverseLerp(vector.Y) * (double) ushort.MaxValue));
         }
 
         ///
@@ -120,7 +122,7 @@ namespace Impostor.Hazel
         public void EndMessage()
         {
             var lastMessageStart = messageStarts.Pop();
-            var length = (ushort)(this.Position - lastMessageStart - 3); // Minus length and type byte
+            ushort length = (ushort)(this.Position - lastMessageStart - 3); // Minus length and type byte
             this.Buffer[lastMessageStart] = (byte)length;
             this.Buffer[lastMessageStart + 1] = (byte)(length >> 8);
         }
@@ -213,7 +215,7 @@ namespace Impostor.Hazel
         {
             fixed (byte* ptr = &this.Buffer[this.Position])
             {
-                var valuePtr = (byte*)&value;
+                byte* valuePtr = (byte*)&value;
 
                 *ptr = *valuePtr;
                 *(ptr + 1) = *(valuePtr + 1);
@@ -300,7 +302,7 @@ namespace Impostor.Hazel
         {
             do
             {
-                var b = (byte)(value & 0xFF);
+                byte b = (byte)(value & 0xFF);
                 if (value >= 0x80)
                 {
                     b |= 0x80;
@@ -315,7 +317,7 @@ namespace Impostor.Hazel
 
         public void Write(MessageWriter msg, bool includeHeader)
         {
-            var offset = 0;
+            int offset = 0;
             if (!includeHeader)
             {
                 switch (msg.SendOption)
@@ -338,8 +340,8 @@ namespace Impostor.Hazel
             byte b;
             unsafe
             {
-                var i = 1;
-                var bp = (byte*)&i;
+                int i = 1;
+                byte* bp = (byte*)&i;
                 b = *bp;
             }
 
index b530f017d170794a8412db40655db63afd12889d..9e81c5cc074252b16b8c9da546a7d63897c1f713 100644 (file)
@@ -12,17 +12,17 @@ namespace Impostor.Hazel
         ReceivedZeroBytes,
         PingsWithoutResponse,
         ReliablePacketWithoutResponse,
-        ConnectionDisconnected,
+        ConnectionDisconnected
     }
 
     /// <summary>
-    ///     Abstract base class for a <see cref="Connection" /> to a remote end point via a network protocol like TCP or UDP.
+    ///     Abstract base class for a <see cref="Connection"/> to a remote end point via a network protocol like TCP or UDP.
     /// </summary>
-    /// <threadsafety static="true" instance="true" />
+    /// <threadsafety static="true" instance="true"/>
     public abstract class NetworkConnection : Connection
     {
         /// <summary>
-        ///     An event that gives us a chance to send well-formed disconnect messages to clients when an internal disconnect happens.
+        /// An event that gives us a chance to send well-formed disconnect messages to clients when an internal disconnect happens.
         /// </summary>
         public Func<HazelInternalErrors, MessageWriter> OnInternalDisconnect;
 
@@ -30,8 +30,8 @@ namespace Impostor.Hazel
         ///     The remote end point of this connection.
         /// </summary>
         /// <remarks>
-        ///     This is the end point of the other device given as an <see cref="System.Net.EndPoint" /> rather than a generic
-        ///     <see cref="ConnectionEndPoint" /> as the base <see cref="Connection" /> does.
+        ///     This is the end point of the other device given as an <see cref="System.Net.EndPoint"/> rather than a generic
+        ///     <see cref="ConnectionEndPoint"/> as the base <see cref="Connection"/> does.
         /// </remarks>
         public IPEndPoint RemoteEndPoint { get; protected set; }
 
@@ -67,14 +67,14 @@ namespace Impostor.Hazel
         }
 
         /// <summary>
-        ///     Called when socket is disconnected internally
+        /// Called when socket is disconnected internally
         /// </summary>
         internal async ValueTask DisconnectInternal(HazelInternalErrors error, string reason)
         {
             var handler = this.OnInternalDisconnect;
             if (handler != null)
             {
-                var messageToRemote = handler(error);
+                MessageWriter messageToRemote = handler(error);
                 if (messageToRemote != null)
                 {
                     try
index e2824b1c913629c8fb2b3464219783a9e3a44ea2..e1d7ffaf84ded796ba55dd53a5599b5344021cc8 100644 (file)
@@ -3,9 +3,9 @@
 namespace Impostor.Hazel
 {
     /// <summary>
-    ///     Abstract base class for a <see cref="ConnectionListener" /> for network based connections.
+    ///     Abstract base class for a <see cref="ConnectionListener"/> for network based connections.
     /// </summary>
-    /// <threadsafety static="true" instance="true" />
+    /// <threadsafety static="true" instance="true"/>
     public abstract class NetworkConnectionListener : ConnectionListener
     {
         /// <summary>
index 77ec05de2b5c69a77cc109fce222f46bf345b021..be9e7a214c98f43c92f192660668545c32e7497b 100644 (file)
@@ -5,13 +5,13 @@ namespace Impostor.Hazel
     public struct NewConnectionEventArgs
     {
         /// <summary>
-        ///     The data received from the client in the handshake.
-        ///     This data is yours. Remember to recycle it.
+        /// The data received from the client in the handshake.
+        /// This data is yours. Remember to recycle it.
         /// </summary>
         public readonly IMessageReader HandshakeData;
 
         /// <summary>
-        ///     The <see cref="Connection" /> to the new client.
+        /// The <see cref="Connection"/> to the new client.
         /// </summary>
         public readonly Connection Connection;
 
index f1256eb61f396e638b72ebe68ee443ccf2b8e0a5..5c9ef9b40468416f0e6e8249b9891fd7ffd82d8b 100644 (file)
@@ -8,7 +8,7 @@ namespace Impostor.Hazel
     ///     A fairly simple object pool for items that will be created a lot.
     /// </summary>
     /// <typeparam name="T">The type that is pooled.</typeparam>
-    /// <threadsafety static="true" instance="true" />
+    /// <threadsafety static="true" instance="true"/>
     public sealed class ObjectPoolCustom<T> where T : IRecyclable
     {
         private int numberCreated;
@@ -32,7 +32,7 @@ namespace Impostor.Hazel
         /// </summary>
         /// <returns></returns>
         private readonly Func<T> objectFactory;
-
+        
         /// <summary>
         ///     Internal constructor for our ObjectPool.
         /// </summary>
@@ -48,7 +48,7 @@ namespace Impostor.Hazel
         internal T GetObject()
         {
 #if HAZEL_BAG
-            if (!pool.TryTake(out var item))
+            if (!pool.TryTake(out T item))
             {
                 Interlocked.Increment(ref numberCreated);
                 item = objectFactory.Invoke();
@@ -85,7 +85,7 @@ namespace Impostor.Hazel
         /// <param name="item">The item to return.</param>
         internal void PutObject(T item)
         {
-            if (inuse.TryRemove(item, out var b))
+            if (inuse.TryRemove(item, out bool b))
             {
 #if HAZEL_BAG
                 pool.Add(item);
index 11baa854ff8513ee7fd150589afd62918cb361b3..c0c4e2127e823e36352f6ffae31f88ee31fe6a0e 100644 (file)
@@ -11,7 +11,7 @@
         Hello = 8,
 
         /// <summary>
-        ///     A single byte of continued existence
+        /// A single byte of continued existence
         /// </summary>
         Ping = 12,
 
index 3c768efc387646d1d17b6f9ebf6282ca5a6aded5..ed7b68dbd47d5206adbf698b6b26d574af503785 100644 (file)
@@ -89,21 +89,21 @@ namespace Impostor.Hazel.Udp
                 return;
             }
 
-            if (numBytes < 3
+            if (numBytes < 3 
                 || buffer[0] != 4 || buffer[1] != 2)
             {
                 this.StartListen();
                 return;
             }
 
-            var ipEnd = (IPEndPoint)endpt;
-            var data = UTF8Encoding.UTF8.GetString(buffer, 2, numBytes - 2);
-            var dataHash = data.GetHashCode();
+            IPEndPoint ipEnd = (IPEndPoint)endpt;
+            string data = UTF8Encoding.UTF8.GetString(buffer, 2, numBytes - 2);
+            int dataHash = data.GetHashCode();
 
             lock (packets)
             {
-                var found = false;
-                for (var i = 0; i < this.packets.Count; ++i)
+                bool found = false;
+                for (int i = 0; i < this.packets.Count; ++i)
                 {
                     var pkt = this.packets[i];
                     if (pkt == null || pkt.Data == null)
@@ -146,17 +146,11 @@ namespace Impostor.Hazel.Udp
         {
             if (this.socket != null)
             {
-                try { this.socket.Shutdown(SocketShutdown.Both); }
-                catch { }
-
-                try { this.socket.Close(); }
-                catch { }
-
-                try { this.socket.Dispose(); }
-                catch { }
-
+                try { this.socket.Shutdown(SocketShutdown.Both); } catch { }
+                try { this.socket.Close(); } catch { }
+                try { this.socket.Dispose(); } catch { }
                 this.socket = null;
             }
         }
     }
-}
+}
\ No newline at end of file
index 32f0e187ae939d5e49c3770bc65b781f8bde7583..5fa1ccac255ac37351a12e52ec9d9abfb428132a 100644 (file)
@@ -26,7 +26,7 @@ namespace Impostor.Hazel.Udp
         ///
         public void SetData(string data)
         {
-            var len = UTF8Encoding.UTF8.GetByteCount(data);
+            int len = UTF8Encoding.UTF8.GetByteCount(data);
             this.data = new byte[len + 2];
             this.data[0] = 4;
             this.data[1] = 2;
@@ -69,17 +69,11 @@ namespace Impostor.Hazel.Udp
         {
             if (this.socket != null)
             {
-                try { this.socket.Shutdown(SocketShutdown.Both); }
-                catch { }
-
-                try { this.socket.Close(); }
-                catch { }
-
-                try { this.socket.Dispose(); }
-                catch { }
-
+                try { this.socket.Shutdown(SocketShutdown.Both); } catch { }
+                try { this.socket.Close(); } catch { }
+                try { this.socket.Dispose(); } catch { }
                 this.socket = null;
             }
         }
     }
-}
+}
\ No newline at end of file
index cb27e2400cdb3ad80c4f023c108df17e446b1354..5125ebe8034522a2e4c8b6b08d73ba81fe34c3c0 100644 (file)
@@ -1,7 +1,9 @@
 ï»¿using System;
+using System.Buffers;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
+using System.Threading.Channels;
 using System.Threading.Tasks;
 using Impostor.Api.Net.Messages;
 using Microsoft.Extensions.ObjectPool;
@@ -12,7 +14,7 @@ namespace Impostor.Hazel.Udp
     /// <summary>
     ///     Represents a client's connection to a server that uses the UDP protocol.
     /// </summary>
-    /// <inheritdoc />
+    /// <inheritdoc/>
     public sealed class UdpClientConnection : UdpConnection
     {
         private static readonly ILogger Logger = Log.ForContext<UdpClientConnection>();
@@ -29,7 +31,7 @@ namespace Impostor.Hazel.Udp
         /// <summary>
         ///     Creates a new UdpClientConnection.
         /// </summary>
-        /// <param name="remoteEndPoint">A <see cref="NetworkEndPoint" /> to connect to.</param>
+        /// <param name="remoteEndPoint">A <see cref="NetworkEndPoint"/> to connect to.</param>
         public UdpClientConnection(IPEndPoint remoteEndPoint, ObjectPool<MessageReader> readerPool, IPMode ipMode = IPMode.IPv4) : base(null, readerPool)
         {
             EndPoint = remoteEndPoint;
@@ -38,7 +40,7 @@ namespace Impostor.Hazel.Udp
 
             _socket = new UdpClient
             {
-                DontFragment = false,
+                DontFragment = false
             };
 
             _reliablePacketTimer = new Timer(ManageReliablePacketsInternal, null, 100, Timeout.Infinite);
@@ -211,11 +213,8 @@ namespace Impostor.Hazel.Udp
         {
             State = ConnectionState.NotConnected;
 
-            try { _socket.Close(); }
-            catch { }
-
-            try { _socket.Dispose(); }
-            catch { }
+            try { _socket.Close(); } catch { }
+            try { _socket.Dispose(); } catch { }
 
             _reliablePacketTimer.Dispose();
             _connectWaitLock.Dispose();
index e8303a4e77e0d9c9a148aeb2d9bc99b589376ac4..a73291bc4e1b68d9b764763fe60656822ecd145e 100644 (file)
@@ -8,6 +8,7 @@ namespace Impostor.Hazel.Udp
 {
     partial class UdpConnection
     {
+
         /// <summary>
         ///     Class to hold packet data
         /// </summary>
@@ -57,7 +58,6 @@ namespace Impostor.Hazel.Udp
                 ResetKeepAliveTimer();
             }
         }
-
         private int keepAliveInterval = 1500;
 
         public int MissingPingsUntilDisconnect { get; set; } = 6;
@@ -109,9 +109,9 @@ namespace Impostor.Hazel.Udp
         // pings should cause a disconnect.
         private async ValueTask SendPing()
         {
-            var id = (ushort)Interlocked.Increment(ref lastIDAllocated);
+            ushort id = (ushort)Interlocked.Increment(ref lastIDAllocated);
 
-            var bytes = new byte[3];
+            byte[] bytes = new byte[3];
             bytes[0] = (byte)UdpSendOption.Ping;
             bytes[1] = (byte)(id >> 8);
             bytes[2] = (byte)id;
@@ -164,4 +164,4 @@ namespace Impostor.Hazel.Udp
             }
         }
     }
-}
+}
\ No newline at end of file
index 9c13f22df966cd90563278d388a6ef0510118ee2..7f439269d2001d8c280b661e987914402343fed8 100644 (file)
@@ -15,25 +15,25 @@ namespace Impostor.Hazel.Udp
         /// </summary>
         /// <remarks>
         ///     <para>
-        ///         For reliable delivery data is resent at specified intervals unless an acknowledgement is received from the
+        ///         For reliable delivery data is resent at specified intervals unless an acknowledgement is received from the 
         ///         receiving device. The ResendTimeout specifies the interval between the packets being resent, each time a packet
-        ///         is resent the interval is increased for that packet until the duration exceeds the <see cref="DisconnectTimeout" /> value.
+        ///         is resent the interval is increased for that packet until the duration exceeds the <see cref="DisconnectTimeout"/> value.
         ///     </para>
         ///     <para>
-        ///         Setting this to its default of 0 will mean the timeout is 2 times the value of the average ping, usually
+        ///         Setting this to its default of 0 will mean the timeout is 2 times the value of the average ping, usually 
         ///         resulting in a more dynamic resend that responds to endpoints on slower or faster connections.
         ///     </para>
         /// </remarks>
         public volatile int ResendTimeout = 0;
 
         /// <summary>
-        ///     Max number of times to resend. 0 == no limit
+        /// Max number of times to resend. 0 == no limit
         /// </summary>
         public volatile int ResendLimit = 0;
 
         /// <summary>
-        ///     A compounding multiplier to back off resend timeout.
-        ///     Applied to ping before first timeout when ResendTimeout == 0.
+        /// A compounding multiplier to back off resend timeout.
+        /// Applied to ping before first timeout when ResendTimeout == 0.
         /// </summary>
         public volatile float ResendPingMultiplier = 2;
 
@@ -48,7 +48,7 @@ namespace Impostor.Hazel.Udp
         internal ConcurrentDictionary<ushort, Packet> reliableDataPacketsSent = new ConcurrentDictionary<ushort, Packet>();
 
         /// <summary>
-        ///     Packet ids that have not been received, but are expected.
+        ///     Packet ids that have not been received, but are expected. 
         /// </summary>
         private HashSet<ushort> reliableDataPacketsMissing = new HashSet<ushort>();
 
@@ -63,7 +63,7 @@ namespace Impostor.Hazel.Udp
         ///     Returns the average ping to this endpoint.
         /// </summary>
         /// <remarks>
-        ///     This returns the average ping for a one-way trip as calculated from the reliable packets that have been sent
+        ///     This returns the average ping for a one-way trip as calculated from the reliable packets that have been sent 
         ///     and acknowledged by the endpoint.
         /// </remarks>
         public float AveragePingMs = 500;
@@ -72,7 +72,7 @@ namespace Impostor.Hazel.Udp
         ///     The maximum times a message should be resent before marking the endpoint as disconnected.
         /// </summary>
         /// <remarks>
-        ///     Reliable packets will be resent at an interval defined in <see cref="ResendTimeout" /> for the number of times
+        ///     Reliable packets will be resent at an interval defined in <see cref="ResendTimeout"/> for the number of times
         ///     specified here. Once a packet has been retransmitted this number of times and has not been acknowledged the
         ///     connection will be marked as disconnected and the <see cref="Connection.Disconnected">Disconnected</see> event
         ///     will be invoked.
@@ -136,10 +136,10 @@ namespace Impostor.Hazel.Udp
                 var connection = this.Connection;
                 if (!this.Acknowledged && connection != null)
                 {
-                    var lifetime = this.Stopwatch.ElapsedMilliseconds;
+                    long lifetime = this.Stopwatch.ElapsedMilliseconds;
                     if (lifetime >= connection.DisconnectTimeout)
                     {
-                        if (connection.reliableDataPacketsSent.TryRemove(this.Id, out var self))
+                        if (connection.reliableDataPacketsSent.TryRemove(this.Id, out Packet self))
                         {
                             await connection.DisconnectInternal(HazelInternalErrors.ReliablePacketWithoutResponse, $"Reliable packet {self.Id} (size={this.Length}) was not ack'd after {lifetime}ms ({self.Retransmissions} resends)");
 
@@ -155,7 +155,7 @@ namespace Impostor.Hazel.Udp
                         if (connection.ResendLimit != 0
                             && this.Retransmissions > connection.ResendLimit)
                         {
-                            if (connection.reliableDataPacketsSent.TryRemove(this.Id, out var self))
+                            if (connection.reliableDataPacketsSent.TryRemove(this.Id, out Packet self))
                             {
                                 await connection.DisconnectInternal(HazelInternalErrors.ReliablePacketWithoutResponse, $"Reliable packet {self.Id} (size={this.Length}) was not ack'd after {self.Retransmissions} resends ({lifetime}ms)");
 
@@ -196,12 +196,12 @@ namespace Impostor.Hazel.Udp
 
         internal async ValueTask<int> ManageReliablePackets()
         {
-            var output = 0;
+            int output = 0;
             if (this.reliableDataPacketsSent.Count > 0)
             {
                 foreach (var kvp in this.reliableDataPacketsSent)
                 {
-                    var pkt = kvp.Value;
+                    Packet pkt = kvp.Value;
 
                     try
                     {
@@ -222,12 +222,12 @@ namespace Impostor.Hazel.Udp
         /// <param name="ackCallback">The callback to make once the packet has been acknowledged.</param>
         protected void AttachReliableID(byte[] buffer, int offset, int sendLength, Action ackCallback = null)
         {
-            var id = (ushort)Interlocked.Increment(ref lastIDAllocated);
+            ushort id = (ushort)Interlocked.Increment(ref lastIDAllocated);
 
             buffer[offset] = (byte)(id >> 8);
             buffer[offset + 1] = (byte)id;
 
-            var packet = Packet.GetObject();
+            Packet packet = Packet.GetObject();
             packet.Set(
                 id,
                 this,
@@ -260,7 +260,7 @@ namespace Impostor.Hazel.Udp
             //Inform keepalive not to send for a while
             ResetKeepAliveTimer();
 
-            var bytes = new byte[data.Length + 3];
+            byte[] bytes = new byte[data.Length + 3];
 
             //Add message type
             bytes[0] = sendOption;
@@ -333,35 +333,35 @@ namespace Impostor.Hazel.Udp
              * 
              * So...
              */
-
+            
             var result = true;
 
             lock (reliableDataPacketsMissing)
             {
                 //Calculate overwritePointer
-                var overwritePointer = (ushort)(reliableReceiveLast - 32768);
+                ushort overwritePointer = (ushort)(reliableReceiveLast - 32768);
 
                 //Calculate if it is a new packet by examining if it is within the range
                 bool isNew;
                 if (overwritePointer < reliableReceiveLast)
-                    isNew = id > reliableReceiveLast || id <= overwritePointer; //Figure (2)
+                    isNew = id > reliableReceiveLast || id <= overwritePointer;     //Figure (2)
                 else
-                    isNew = id > reliableReceiveLast && id <= overwritePointer; //Figure (3)
-
+                    isNew = id > reliableReceiveLast && id <= overwritePointer;     //Figure (3)
+                
                 //If it's new or we've not received anything yet
                 if (isNew)
                 {
                     // Mark items between the most recent receive and the id received as missing
                     if (id > reliableReceiveLast)
                     {
-                        for (var i = (ushort)(reliableReceiveLast + 1); i < id; i++)
+                        for (ushort i = (ushort)(reliableReceiveLast + 1); i < id; i++)
                         {
                             reliableDataPacketsMissing.Add(i);
                         }
                     }
                     else
                     {
-                        var cnt = (ushort.MaxValue - reliableReceiveLast) + id;
+                        int cnt = (ushort.MaxValue - reliableReceiveLast) + id;
                         for (ushort i = 1; i < cnt; ++i)
                         {
                             reliableDataPacketsMissing.Add((ushort)(i + reliableReceiveLast));
@@ -371,7 +371,7 @@ namespace Impostor.Hazel.Udp
                     //Update the most recently received
                     reliableReceiveLast = id;
                 }
-
+                
                 //Else it could be a missing packet
                 else
                 {
@@ -382,7 +382,7 @@ namespace Impostor.Hazel.Udp
                     }
                 }
             }
-
+            
             //Send an acknowledgement
             await SendAck(id);
 
@@ -397,13 +397,13 @@ namespace Impostor.Hazel.Udp
         {
             this.pingsSinceAck = 0;
 
-            var id = (ushort)((bytes[1] << 8) + bytes[2]);
+            ushort id = (ushort)((bytes[1] << 8) + bytes[2]);
             AcknowledgeMessageId(id);
 
             if (bytes.Length == 4)
             {
-                var recentPackets = bytes[3];
-                for (var i = 1; i <= 8; ++i)
+                byte recentPackets = bytes[3];
+                for (int i = 1; i <= 8; ++i)
                 {
                     if ((recentPackets & 1) != 0)
                     {
@@ -420,7 +420,7 @@ namespace Impostor.Hazel.Udp
         private void AcknowledgeMessageId(ushort id)
         {
             // Dispose of timer and remove from dictionary
-            if (reliableDataPacketsSent.TryRemove(id, out var packet))
+            if (reliableDataPacketsSent.TryRemove(id, out Packet packet))
             {
                 float rt = packet.Stopwatch.ElapsedMilliseconds;
 
@@ -432,7 +432,7 @@ namespace Impostor.Hazel.Udp
                     this.AveragePingMs = Math.Max(50, this.AveragePingMs * .7f + rt * .3f);
                 }
             }
-            else if (this.activePingPackets.TryRemove(id, out var pingPkt))
+            else if (this.activePingPackets.TryRemove(id, out PingPacket pingPkt))
             {
                 float rt = pingPkt.Stopwatch.ElapsedMilliseconds;
 
@@ -455,7 +455,7 @@ namespace Impostor.Hazel.Udp
             byte recentPackets = 0;
             lock (this.reliableDataPacketsMissing)
             {
-                for (var i = 1; i <= 8; ++i)
+                for (int i = 1; i <= 8; ++i)
                 {
                     if (!this.reliableDataPacketsMissing.Contains((ushort)(id - i)))
                     {
@@ -464,12 +464,12 @@ namespace Impostor.Hazel.Udp
                 }
             }
 
-            var bytes = new byte[]
+            byte[] bytes = new byte[]
             {
                 (byte)UdpSendOption.Acknowledgement,
                 (byte)(id >> 8),
                 (byte)(id >> 0),
-                recentPackets,
+                recentPackets
             };
 
             try
index 4106bfe14e23852c590f8472fd34ee0494f73ae8..5288d3ce225d909a2458062b7af93598996bf78a 100644 (file)
@@ -34,7 +34,7 @@ namespace Impostor.Hazel.Udp
             Pipeline = Channel.CreateUnbounded<byte[]>(new UnboundedChannelOptions
             {
                 SingleReader = true,
-                SingleWriter = true,
+                SingleWriter = true
             });
         }
 
@@ -113,13 +113,13 @@ namespace Impostor.Hazel.Udp
         /// <param name="length"></param>
         protected abstract ValueTask WriteBytesToConnection(byte[] bytes, int length);
 
-        /// <inheritdoc />
+        /// <inheritdoc/>
         public override async ValueTask SendAsync(IMessageWriter msg)
         {
             if (this._state != ConnectionState.Connected)
                 throw new InvalidOperationException("Could not send data as this Connection is not connected. Did you disconnect?");
 
-            var buffer = new byte[msg.Length];
+            byte[] buffer = new byte[msg.Length];
             Buffer.BlockCopy(msg.Buffer, 0, buffer, 0, msg.Length);
 
             switch (msg.SendOption)
@@ -139,13 +139,13 @@ namespace Impostor.Hazel.Udp
             }
         }
 
-        /// <inheritdoc />
+        /// <inheritdoc/>
         /// <remarks>
         ///     <include file="DocInclude/common.xml" path="docs/item[@name='Connection_SendBytes_General']/*" />
         ///     <para>
-        ///         Udp connections can currently send messages using <see cref="SendOption.None" /> and
-        ///         <see cref="SendOption.Reliable" />. Fragmented messages are not currently supported and will default to
-        ///         <see cref="SendOption.None" /> until implemented.
+        ///         Udp connections can currently send messages using <see cref="SendOption.None"/> and
+        ///         <see cref="SendOption.Reliable"/>. Fragmented messages are not currently supported and will default to
+        ///         <see cref="SendOption.None"/> until implemented.
         ///     </para>
         /// </remarks>
         public override async ValueTask SendBytes(byte[] bytes, MessageType sendOption = MessageType.Unreliable)
@@ -153,12 +153,12 @@ namespace Impostor.Hazel.Udp
             //Add header information and send
             await HandleSend(bytes, (byte)sendOption);
         }
-
+        
         /// <summary>
         ///     Handles the reliable/fragmented sending from this connection.
         /// </summary>
         /// <param name="data">The data being sent.</param>
-        /// <param name="sendOption">The <see cref="SendOption" /> specified as its byte value.</param>
+        /// <param name="sendOption">The <see cref="SendOption"/> specified as its byte value.</param>
         /// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
         /// <returns>The bytes that should actually be sent.</returns>
         protected async ValueTask HandleSend(byte[] data, byte sendOption, Action ackCallback = null)
@@ -170,7 +170,7 @@ namespace Impostor.Hazel.Udp
                 case (byte)UdpSendOption.Hello:
                     await ReliableSend(sendOption, data, ackCallback);
                     break;
-
+                                    
                 //Treat all else as unreliable
                 default:
                     await UnreliableSend(sendOption, data);
@@ -226,16 +226,14 @@ namespace Impostor.Hazel.Udp
                     {
                         await DisconnectRemote("The remote sent a disconnect request", reader);
                     }
-
                     break;
-
+                    
                 //Treat everything else as unreliable
                 default:
                     using (var reader = message.Copy(1))
                     {
                         await InvokeDataReceived(reader, MessageType.Unreliable);
                     }
-
                     Statistics.LogUnreliableReceive(message.Length - 1, message.Length);
                     break;
             }
@@ -260,7 +258,7 @@ namespace Impostor.Hazel.Udp
         /// <param name="length"></param>
         async ValueTask UnreliableSend(byte sendOption, byte[] data, int offset, int length)
         {
-            var bytes = new byte[length + 1];
+            byte[] bytes = new byte[length + 1];
 
             //Add message type
             bytes[0] = sendOption;
@@ -295,8 +293,8 @@ namespace Impostor.Hazel.Udp
 
             return HandleSend(actualBytes, (byte)UdpSendOption.Hello, acknowledgeCallback);
         }
-
-        /// <inheritdoc />
+                
+        /// <inheritdoc/>
         protected override void Dispose(bool disposing)
         {
             if (disposing)
index 782bf613720b608677aac23164620bfa0fa48582..573a00cbfad59f98eed9c936db7b52e30241ef96 100644 (file)
@@ -4,6 +4,7 @@ using System.Collections.Concurrent;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
+using System.Threading.Channels;
 using System.Threading.Tasks;
 using Microsoft.Extensions.ObjectPool;
 using Serilog;
@@ -19,12 +20,11 @@ namespace Impostor.Hazel.Udp
         private static readonly ILogger Logger = Log.ForContext<UdpConnectionListener>();
 
         /// <summary>
-        ///     A callback for early connection rejection.
-        ///     * Return false to reject connection.
-        ///     * A null response is ok, we just won't send anything.
+        /// A callback for early connection rejection. 
+        /// * Return false to reject connection.
+        /// * A null response is ok, we just won't send anything.
         /// </summary>
         public AcceptConnectionCheck AcceptConnection;
-
         public delegate bool AcceptConnectionCheck(IPEndPoint endPoint, byte[] input, out byte[] response);
 
         private readonly UdpClient _socket;
@@ -37,7 +37,7 @@ namespace Impostor.Hazel.Udp
         private Task _executingTask;
 
         /// <summary>
-        ///     Creates a new UdpConnectionListener for the given <see cref="IPAddress" />, port and <see cref="IPMode" />.
+        ///     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>
         /// <param name="ipMode"></param>
@@ -72,7 +72,7 @@ namespace Impostor.Hazel.Udp
         }
 
         public int ConnectionCount => this._allConnections.Count;
-
+        
         private async void ManageReliablePackets(object state)
         {
             foreach (var kvp in _allConnections)
index b90d7b15ff69cbd965182feef859c8bd6ac84779..64881d3daf2b46934c6621f76665906137aa8c39 100644 (file)
@@ -72,4 +72,4 @@ namespace Impostor.Hazel.Udp
             _timer.Dispose();
         }
     }
-}
+}
\ No newline at end of file
index 8c6cc067a2b0f3a9f808d1f72b3b2d7ad36f44b4..8d3426e38a2917f165a9ebac8ccd2590cc6472b7 100644 (file)
@@ -9,14 +9,14 @@ namespace Impostor.Hazel.Udp
     /// <summary>
     ///     Represents a servers's connection to a client that uses the UDP protocol.
     /// </summary>
-    /// <inheritdoc />
+    /// <inheritdoc/>
     internal sealed class UdpServerConnection : UdpConnection
     {
         /// <summary>
         ///     The connection listener that we use the socket of.
         /// </summary>
         /// <remarks>
-        ///     Udp server connections utilize the same socket in the listener for sends/receives, this is the listener that
+        ///     Udp server connections utilize the same socket in the listener for sends/receives, this is the listener that 
         ///     created this connection and is hence the listener this conenction sends and receives via.
         /// </remarks>
         public UdpConnectionListener Listener { get; private set; }
@@ -63,7 +63,7 @@ namespace Impostor.Hazel.Udp
                 if (this._state != ConnectionState.Connected) return false;
                 this._state = ConnectionState.NotConnected;
             }
-
+            
             var bytes = EmptyDisconnectBytes;
             if (data != null && data.Length > 0)
             {