]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
I like this idea, but why memmory?
authorForest <chocozilla@gmail.com>
Tue, 18 Dec 2018 20:00:26 +0000 (12:00 -0800)
committerForest <chocozilla@gmail.com>
Tue, 18 Dec 2018 20:00:26 +0000 (12:00 -0800)
Hazel/Udp/UdpConnection.Reliable.cs
Hazel/Udp/UdpConnectionListener.cs

index 8145ce151674d19ea91d2dea255fd26d72b4d26b..16554dacb7d573e3fcba7ff29e08b63b62ce3204 100644 (file)
@@ -240,7 +240,7 @@ namespace Hazel.Udp
 
                         Trace.WriteLine("Resend.");
                     },
-                    resendTimeout > 0 ? resendTimeout : (int)Math.Max(40, Math.Min(AveragePingMs * 4, 750)),
+                    resendTimeout > 0 ? resendTimeout : (int)Math.Max(100, Math.Min(AveragePingMs * 4, 1500)),
                     ackCallback
                 );
             }
index 86a32f9b60ce25b98e3aeace128d73d7a31b923d..bcefc867144ab8d580a24bfa802c8124f2e97b8a 100644 (file)
@@ -17,6 +17,8 @@ namespace Hazel.Udp
     {
         public const int BufferSize = ushort.MaxValue / 4;
 
+        public int MinConnectionLength = 0;
+
         /// <summary>
         ///     The socket listening for connections.
         /// </summary>
@@ -26,7 +28,7 @@ namespace Hazel.Udp
         ///     The connections we currently hold
         /// </summary>
         ConcurrentDictionary<EndPoint, UdpServerConnection> allConnections = new ConcurrentDictionary<EndPoint, UdpServerConnection>();
-
+        
         public int ConnectionCount { get { return this.allConnections.Count; } }
         /// <summary>
         ///     Creates a new UdpConnectionListener for the given <see cref="IPAddress"/>, port and <see cref="IPMode"/>.
@@ -165,23 +167,30 @@ namespace Hazel.Udp
             //Begin receiving again
             StartListeningForData();
 
-            bool aware = true;
-            bool isHello = message.Buffer[0] == (byte)UdpSendOption.Hello;
+            bool aware;
+            bool isHello = message.Buffer[0] == (byte)UdpSendOption.Hello
+                && message.Length >= MinConnectionLength;
 
             //If we're aware of this connection use the one already
             //If this is a new client then connect with them!
-            UdpServerConnection connection = this.allConnections.GetOrAdd(
-                remoteEndPoint, 
-                key => { aware = false; return new UdpServerConnection(this, key, IPMode); });
-
-            if (!aware)
+            UdpServerConnection connection;
+            if (!(aware = this.allConnections.TryGetValue(remoteEndPoint, out connection)))
             {
-                //Check for malformed connection attempts
-                if (!isHello)
+                lock (this.allConnections)
                 {
-                    Interlocked.Decrement(ref ActiveCallbacks);
-                    message.Recycle();
-                    return;
+                    if (!(aware = this.allConnections.TryGetValue(remoteEndPoint, out connection)))
+                    {
+                        //Check for malformed connection attempts
+                        if (!isHello)
+                        {
+                            Interlocked.Decrement(ref ActiveCallbacks);
+                            message.Recycle();
+                            return;
+                        }
+
+                        connection = new UdpServerConnection(this, remoteEndPoint, this.IPMode);
+                        this.allConnections.TryAdd(remoteEndPoint, connection);
+                    }
                 }
             }