Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2 from mfalkvidd/configurable-server-timeout
Browse files Browse the repository at this point in the history
Add configurable server timeout
  • Loading branch information
boyvinall authored Mar 20, 2019
2 parents 404dd15 + b64da42 commit 9b6f7fd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/DTLS.Net/ServerHandshake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ internal class ServerHandshake
public Org.BouncyCastle.Crypto.AsymmetricKeyParameter PrivateKey { get; set; }
public Version ServerVersion { get; set; }
public Sessions Sessions { get; set; }
private const int HANDSHAKE_DWELL_TIME = 10;
public static int HandshakeTimeout { get; set; } = 5000;



Expand Down Expand Up @@ -72,15 +74,15 @@ public void ProcessHandshake(DTLSRecord record)
if ((session != null) && session.IsEncypted(record))
{
int count = 0;
while ((session.Cipher == null) && (count < 50))
while ((session.Cipher == null) && (count < (HandshakeTimeout / HANDSHAKE_DWELL_TIME)))
{
System.Threading.Thread.Sleep(10);
System.Threading.Thread.Sleep(HANDSHAKE_DWELL_TIME);
count++;
}

if (session.Cipher == null)
{
throw new Exception();
{
throw new Exception($"HandshakeTimeout: >{HandshakeTimeout}");
}

if (session.Cipher != null)
Expand Down

0 comments on commit 9b6f7fd

Please sign in to comment.